46#include "moc_qgslayout.cpp"
55 , mGridSettings( this )
60 setBackgroundBrush( Qt::NoBrush );
61 mItemsModel = std::make_unique<QgsLayoutModel>(
this );
67 mUndoStack->blockCommands(
true );
69 deleteAndRemoveMultiFrames();
77 QList<QGraphicsItem *> itemList = items();
82 for ( QGraphicsItem *item : std::as_const( itemList ) )
99 QDomDocument currentDoc;
102 QDomElement elem =
writeXml( currentDoc, context );
103 currentDoc.appendChild( elem );
105 auto newLayout = std::make_unique< QgsLayout >( mProject );
107 newLayout->loadFromTemplate( currentDoc, context,
true, &ok );
113 return newLayout.release();
121 mPageCollection->addPage( page );
122 mUndoStack->stack()->clear();
127 deleteAndRemoveMultiFrames();
130 const QList<QGraphicsItem *> itemList = items();
131 for ( QGraphicsItem *item : itemList )
135 if ( cItem && !pItem )
137 removeLayoutItemPrivate( cItem );
140 mItemsModel->clear();
142 mPageCollection->clear();
143 mUndoStack->stack()->clear();
153 return mItemsModel.get();
158 QList<QgsLayoutItem *> layoutItemList;
160 const QList<QGraphicsItem *> graphicsItemList = selectedItems();
161 for ( QGraphicsItem *item : graphicsItemList )
164 if ( layoutItem && ( includeLockedItems || !layoutItem->
isLocked() ) )
166 layoutItemList.push_back( layoutItem );
170 return layoutItemList;
189 const QList<QGraphicsItem *> selectedItemList = selectedItems();
190 for ( QGraphicsItem *item : selectedItemList )
194 layoutItem->setSelected(
false );
203 bool result = mItemsModel->reorderItemUp( item );
204 if ( result && !deferUpdate )
216 bool result = mItemsModel->reorderItemDown( item );
217 if ( result && !deferUpdate )
229 bool result = mItemsModel->reorderItemToTop( item );
230 if ( result && !deferUpdate )
242 bool result = mItemsModel->reorderItemToBottom( item );
243 if ( result && !deferUpdate )
254 QList<QgsLayoutItem *> itemList;
258 if ( item->uuid() == uuid )
260 else if ( includeTemplateUuids && item->mTemplateUuid == uuid )
269 QList<QgsLayoutItem *> itemList;
273 if ( item->mTemplateUuid == uuid )
282 const QList<QGraphicsItem *> itemList = items();
283 for ( QGraphicsItem *item : itemList )
286 if ( layoutItem && layoutItem->
id() ==
id )
298 if ( mf->uuid() == uuid )
300 else if ( includeTemplateUuids && mf->mTemplateUuid == uuid )
309 return layoutItemAt( position,
nullptr, ignoreLocked, searchTolerance );
315 QList<QGraphicsItem *> itemList;
316 if ( searchTolerance == 0 )
318 itemList = items( position, Qt::IntersectsItemShape, Qt::DescendingOrder );
322 itemList = items( QRectF( position.x() - searchTolerance, position.y() - searchTolerance, 2 * searchTolerance, 2 * searchTolerance ), Qt::IntersectsItemShape, Qt::DescendingOrder );
325 bool foundBelowItem =
false;
326 for ( QGraphicsItem *graphicsItem : std::as_const( itemList ) )
330 if ( layoutItem && !paperItem )
334 if ( ( ! belowItem || foundBelowItem ) && ( !ignoreLocked || !layoutItem->
isLocked() ) )
339 return layoutItemAt( position, layoutItem, ignoreLocked, searchTolerance );
346 if ( layoutItem == belowItem )
349 foundBelowItem =
true;
359 return mRenderContext->measurementConverter().convert( measurement, mUnits ).length();
364 return mRenderContext->measurementConverter().convert( size, mUnits ).toQSizeF();
369 return mRenderContext->measurementConverter().convert( point, mUnits ).toQPointF();
374 return mRenderContext->measurementConverter().convert(
QgsLayoutMeasurement( length, mUnits ), unit );
379 return mRenderContext->measurementConverter().convert(
QgsLayoutSize( size.width(), size.height(), mUnits ), unit );
384 return mRenderContext->measurementConverter().convert(
QgsLayoutPoint( point.x(), point.y(), mUnits ), unit );
389 return *mRenderContext;
394 return *mRenderContext;
399 return *mReportContext;
404 return *mReportContext;
409 mGridSettings.loadFromSettings();
410 mPageCollection->redraw();
415 return mPageCollection->
guides();
420 return mPageCollection->
guides();
428 if ( mReportContext->layer() )
437 mCustomProperties.setValue( key, value );
439 if ( key.startsWith( QLatin1String(
"variable" ) ) )
445 return mCustomProperties.value( key, defaultValue );
450 mCustomProperties.remove( key );
455 return mCustomProperties.keys();
465 QList< QgsLayoutItemMap * > maps;
468 double largestMapArea = 0;
471 double area = map->rect().width() * map->rect().height();
472 if ( area > largestMapArea )
474 largestMapArea = area;
483 mWorldFileMapId = map ? map->
uuid() : QString();
484 mProject->setDirty(
true );
489 return mPageCollection.get();
494 return mPageCollection.get();
503 const auto constItems = items();
504 for (
const QGraphicsItem *item : constItems )
511 if ( !isPage || !ignorePages )
519 itemBounds = layoutItem->mapToScene( layoutItem->rect() ).boundingRect();
522 itemBounds = item->sceneBoundingRect();
524 if ( bounds.isValid() )
525 bounds = bounds.united( itemBounds );
531 if ( bounds.isValid() && margin > 0.0 )
534 double maxWidth = mPageCollection->maximumPageWidth();
535 bounds.adjust( -maxWidth * margin, -maxWidth * margin, maxWidth * margin, maxWidth * margin );
548 const QList<QGraphicsItem *> itemList = items();
549 for ( QGraphicsItem *item : itemList )
554 if ( visibleOnly && !layoutItem->isVisible() )
558 if ( bounds.isValid() )
559 bounds = bounds.united( item->sceneBoundingRect() );
561 bounds = item->sceneBoundingRect();
570 addLayoutItemPrivate( item );
574 undoText = tr(
"Create %1" ).arg( metadata->visibleName() );
578 undoText = tr(
"Create Item" );
580 if ( !mUndoStack->isBlocked() )
586 std::unique_ptr< QgsLayoutItemDeleteUndoCommand > deleteCommand;
587 if ( !mUndoStack->isBlocked() )
589 mUndoStack->beginMacro( tr(
"Delete Items" ) );
590 deleteCommand = std::make_unique<QgsLayoutItemDeleteUndoCommand>( item, tr(
"Delete Item" ) );
592 removeLayoutItemPrivate( item );
595 mUndoStack->push( deleteCommand.release() );
596 mUndoStack->endMacro();
605 if ( !mMultiFrames.contains( multiFrame ) )
606 mMultiFrames << multiFrame;
611 mMultiFrames.removeAll( multiFrame );
621 QFile templateFile( path );
622 if ( !templateFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
627 QDomDocument saveDocument;
628 QDomElement elem =
writeXml( saveDocument, context );
629 saveDocument.appendChild( elem );
631 if ( templateFile.write( saveDocument.toByteArray() ) == -1 )
642 QList< QgsLayoutItem * > result;
662 QDomNodeList itemsNodes = doc.elementsByTagName( QStringLiteral(
"LayoutItem" ) );
663 for (
int i = 0; i < itemsNodes.count(); ++i )
665 QDomNode itemNode = itemsNodes.at( i );
666 if ( itemNode.isElement() )
668 itemNode.toElement().removeAttribute( QStringLiteral(
"uuid" ) );
671 QDomNodeList multiFrameNodes = doc.elementsByTagName( QStringLiteral(
"LayoutMultiFrame" ) );
672 for (
int i = 0; i < multiFrameNodes.count(); ++i )
674 QDomNode multiFrameNode = multiFrameNodes.at( i );
675 if ( multiFrameNode.isElement() )
677 multiFrameNode.toElement().removeAttribute( QStringLiteral(
"uuid" ) );
678 QDomNodeList frameNodes = multiFrameNode.toElement().elementsByTagName( QStringLiteral(
"childFrame" ) );
679 QDomNode itemNode = frameNodes.at( i );
680 if ( itemNode.isElement() )
682 itemNode.toElement().removeAttribute( QStringLiteral(
"uuid" ) );
690 QDomElement layoutElem = doc.documentElement();
691 if ( layoutElem.isNull() )
696 bool loadOk =
readXml( layoutElem, doc, context );
716 return mUndoStack.get();
721 return mUndoStack.get();
736 void saveState( QDomDocument &stateDoc )
const override
739 QDomElement documentElement = stateDoc.createElement( QStringLiteral(
"UndoState" ) );
740 mLayout->writeXmlLayoutSettings( documentElement, stateDoc, QgsReadWriteContext() );
741 stateDoc.appendChild( documentElement );
751 mLayout->readXmlLayoutSettings( stateDoc.documentElement(), stateDoc, QgsReadWriteContext() );
752 mLayout->project()->setDirty(
true );
757 QgsLayout *mLayout =
nullptr;
768 if ( items.size() < 2 )
774 mUndoStack->beginMacro( tr(
"Group Items" ) );
775 auto itemGroup = std::make_unique<QgsLayoutItemGroup>(
this );
778 itemGroup->addItem( item );
783 auto c = std::make_unique<QgsLayoutItemGroupUndoCommand>( QgsLayoutItemGroupUndoCommand::Grouped, returnGroup,
this, tr(
"Group Items" ) );
784 mUndoStack->push(
c.release() );
785 mProject->setDirty(
true );
787 mUndoStack->endMacro();
795 QList<QgsLayoutItem *> ungroupedItems;
798 return ungroupedItems;
801 mUndoStack->beginMacro( tr(
"Ungroup Items" ) );
804 auto c = std::make_unique<QgsLayoutItemGroupUndoCommand>( QgsLayoutItemGroupUndoCommand::Ungrouped, group,
this, tr(
"Ungroup Items" ) );
805 mUndoStack->push(
c.release() );
807 mProject->setDirty(
true );
809 ungroupedItems = group->
items();
813 mUndoStack->endMacro();
815 return ungroupedItems;
820 const QList< QGraphicsItem * > constItems = items();
821 for (
const QGraphicsItem *item : constItems )
827 if ( !layoutItem->
accept( visitor ) )
835 mUndoStack->blockCommands(
true );
836 mPageCollection->beginPageSizeChange();
838 mPageCollection->reflow();
839 mPageCollection->endPageSizeChange();
840 mUndoStack->blockCommands(
false );
844void QgsLayout::writeXmlLayoutSettings( QDomElement &element, QDomDocument &document,
const QgsReadWriteContext & )
const
846 mCustomProperties.
writeXml( element, document );
848 element.setAttribute( QStringLiteral(
"worldFileMap" ), mWorldFileMapId );
849 element.setAttribute( QStringLiteral(
"printResolution" ), mRenderContext->
dpi() );
854 QDomElement element = document.createElement( QStringLiteral(
"Layout" ) );
857 return object->writeXml( element, document, context );
860 save( &mGridSettings );
861 save( mPageCollection.get() );
864 const QList<QGraphicsItem *> itemList = items();
865 for (
const QGraphicsItem *graphicsItem : itemList )
872 item->writeXml( element, document, context );
879 if ( mf->frameCount() > 0 )
880 mf->writeXml( element, document, context );
883 writeXmlLayoutSettings( element, document, context );
887bool QgsLayout::readXmlLayoutSettings(
const QDomElement &layoutElement,
const QDomDocument &,
const QgsReadWriteContext & )
889 mCustomProperties.
readXml( layoutElement );
891 mWorldFileMapId = layoutElement.attribute( QStringLiteral(
"worldFileMap" ) );
892 mRenderContext->
setDpi( layoutElement.attribute( QStringLiteral(
"printResolution" ), QStringLiteral(
"300" ) ).toDouble() );
902 mItemsModel->rebuildZList();
907void QgsLayout::removeLayoutItemPrivate(
QgsLayoutItem *item )
909 mItemsModel->setItemRemoved( item );
916 emit itemRemoved( item );
922void QgsLayout::deleteAndRemoveMultiFrames()
924 qDeleteAll( mMultiFrames );
925 mMultiFrames.clear();
928QPointF QgsLayout::minPointFromXml(
const QDomElement &elem )
const
930 double minX = std::numeric_limits<double>::max();
931 double minY = std::numeric_limits<double>::max();
932 const QDomNodeList itemList = elem.elementsByTagName( QStringLiteral(
"LayoutItem" ) );
934 for (
int i = 0; i < itemList.size(); ++i )
936 const QDomElement currentItemElem = itemList.at( i ).toElement();
941 minX = std::min( minX, layoutPoint.x() );
942 minY = std::min( minY, layoutPoint.y() );
945 return found ? QPointF( minX, minY ) : QPointF( 0, 0 );
950 int counter = mItemsModel->zOrderListSize();
951 const QList<QgsLayoutItem *> zOrderList = mItemsModel->zOrderList();
953 if ( addUndoCommands )
955 mUndoStack->beginMacro( tr(
"Change Item Stacking" ) );
961 if ( addUndoCommands )
963 mUndoStack->beginCommand( currentItem, QString() );
965 currentItem->setZValue( counter );
966 if ( addUndoCommands )
968 mUndoStack->endCommand();
973 if ( addUndoCommands )
975 mUndoStack->endMacro();
981 if ( layoutElement.nodeName() != QLatin1String(
"Layout" ) )
988 return object->readXml( layoutElement, document, context );
991 std::unique_ptr< QgsScopedRuntimeProfile > profile;
993 profile = std::make_unique< QgsScopedRuntimeProfile >( tr(
"Read layout settings" ), QStringLiteral(
"projectload" ) );
995 blockSignals(
true );
996 readXmlLayoutSettings( layoutElement, document, context );
997 blockSignals(
false );
1000 profile->switchTask( tr(
"Load pages" ) );
1001 restore( mPageCollection.get() );
1003 profile->switchTask( tr(
"Load snapping settings" ) );
1004 restore( &mSnapper );
1006 profile->switchTask( tr(
"Load grid settings" ) );
1007 restore( &mGridSettings );
1010 profile->switchTask( tr(
"Restore items" ) );
1020 QList< QgsLayoutItem * > newItems;
1021 QList< QgsLayoutMultiFrame * > newMultiFrames;
1026 int zOrderOffset = mItemsModel->zOrderListSize();
1028 QPointF pasteShiftPos;
1029 int pageNumber = -1;
1035 QPointF minItemPos = minPointFromXml( parentElement );
1038 pasteShiftPos = *position - minItemPos;
1041 pageNumber = mPageCollection->pageNumberForPoint( *position );
1045 std::unique_ptr< QgsScopedRuntimeProfile > profile;
1047 profile = std::make_unique< QgsScopedRuntimeProfile >( tr(
"Read items" ), QStringLiteral(
"projectload" ) );
1052 const QDomNodeList multiFrameList = parentElement.elementsByTagName( QStringLiteral(
"LayoutMultiFrame" ) );
1053 for (
int i = 0; i < multiFrameList.size(); ++i )
1055 const QDomElement multiFrameElem = multiFrameList.at( i ).toElement();
1056 const int itemType = multiFrameElem.attribute( QStringLiteral(
"type" ) ).toInt();
1062 profile->switchTask( tr(
"Load %1" ).arg( metadata->visibleName() ) );
1072 mf->readXml( multiFrameElem, document, context );
1075 mf->setCreateUndoCommands(
true );
1090 newMultiFrames << m;
1093 const QDomNodeList layoutItemList = parentElement.childNodes();
1094 for (
int i = 0; i < layoutItemList.size(); ++i )
1096 const QDomElement currentItemElem = layoutItemList.at( i ).toElement();
1097 if ( currentItemElem.nodeName() != QLatin1String(
"LayoutItem" ) )
1100 const int itemType = currentItemElem.attribute( QStringLiteral(
"type" ) ).toInt();
1106 profile->switchTask( tr(
"Load %1" ).arg( metadata->visibleName() ) );
1117 item->readXml( currentItemElem, document, context );
1123 item->attemptMove( posOnPage,
true,
false, pageNumber );
1127 item->attemptMoveBy( pasteShiftPos.x(), pasteShiftPos.y() );
1143 label->setTextFormat( textFormat );
1147 if ( item->isGroupMember() )
1151 QList<QgsLayoutItem *>
groupItems = group->items();
1153 group->removeItems();
1156 group->addItem( groupItem );
1158 group->addItem( html->
frame( 0 ) );
1161 newMultiFrames << html;
1169 layoutItem->setZValue( layoutItem->zValue() + zOrderOffset );
1170 newItems << layoutItem;
1177 std::unique_ptr< QgsScopedRuntimeProfile > itemProfile;
1180 profile->switchTask( tr(
"Finalize restore" ) );
1185 itemProfile = std::make_unique< QgsScopedRuntimeProfile >( item->
displayName(), QStringLiteral(
"projectload" ) );
1188 itemProfile.reset();
1193 itemProfile = std::make_unique< QgsScopedRuntimeProfile >( mf->displayName(), QStringLiteral(
"projectload" ) );
1194 mf->finalizeRestoreFromXml();
1196 itemProfile.reset();
1201 item->mTemplateUuid.clear();
1205 mf->mTemplateUuid.clear();
1213 profile->switchTask( tr(
"Update model" ) );
1214 mItemsModel->rebuildZList();
1224void QgsLayout::itemBackgroundTaskCountChanged(
int count )
1226 QgsLayoutItem *item = qobject_cast<QgsLayoutItem *>( sender() );
1231 mBackgroundTaskCount.insert( item, count );
1233 mBackgroundTaskCount.remove( item );
1237 for (
auto it = mBackgroundTaskCount.constBegin(); it != mBackgroundTaskCount.constEnd(); ++it )
1239 total += it.value();
LayoutUnit
Layout measurement units.
@ Millimeters
Millimeters.
@ Percentage
Percentage of another measurement (e.g., canvas size, feature size).
Base class for commands to undo/redo layout and layout object changes.
virtual void saveState(QDomDocument &stateDoc) const =0
Saves the state of the object to the specified stateDoc.
virtual void restoreState(QDomDocument &stateDoc)=0
Restores the state of the object from the specified stateDoc.
static QgsLayoutItemRegistry * layoutItemRegistry()
Returns the application's layout item registry, used for layout item types.
static QgsRuntimeProfiler * profiler()
Returns the application runtime profiler.
static bool isCompositionTemplate(const QDomDocument &document)
Check if the given document is a composition template.
static QDomDocument convertCompositionTemplate(const QDomDocument &document, QgsProject *project)
Convert a composition template document to a layout template.
static QgsExpressionContextScope * layoutScope(const QgsLayout *layout)
Creates a new scope which contains variables and functions relating to a QgsLayout layout.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Stores and manages the snap guides used by a layout.
QList< QgsLayoutGuide * > guides()
Returns a list of all guides contained in the collection.
A container for grouping several QgsLayoutItems.
void removeItems()
Removes all items from the group (but does not delete them).
QList< QgsLayoutItem * > items() const
Returns a list of items contained by the group.
static QgsLayoutItemHtml * createFromLabel(QgsLayoutItemLabel *label)
Returns a new QgsLayoutItemHtml matching the content and rendering of a given label.
A layout item subclass for text labels.
@ ModeHtml
Label displays rendered HTML content.
Layout graphical items for displaying a map.
Item representing the paper in a layout.
void setPageSize(const QgsLayoutSize &size)
Sets the size of the page.
Base class for graphical items within a QgsLayout.
virtual void cleanup()
Called just before a batch of items are deleted, allowing them to run cleanup tasks.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
QgsLayoutItemGroup * parentGroup() const
Returns the item's parent group, if the item is part of a QgsLayoutItemGroup group.
virtual void setSelected(bool selected)
Sets whether the item should be selected.
bool isLocked() const
Returns true if the item is locked, and cannot be interacted with using the mouse.
int page() const
Returns the page the item is currently on, with the first page returning 0.
virtual void finalizeRestoreFromXml()
Called after all pending items have been restored from XML.
int type() const override
Returns a unique graphics item type identifier.
virtual QString displayName() const
Gets item display name.
virtual QString uuid() const
Returns the item identification string.
QString id() const
Returns the item's ID name.
void backgroundTaskCountChanged(int count)
Emitted whenever the number of background tasks an item is executing changes.
Provides a method of storing measurements for use in QGIS layouts using a variety of different measur...
QgsLayoutFrame * frame(int index) const
Returns the child frame at a specified index from the multiframe.
A manager for a collection of pages in a layout.
Provides a method of storing points, consisting of an x and y coordinate, for use in QGIS layouts.
static QgsLayoutPoint decodePoint(const QString &string)
Decodes a point from a string.
Stores information relating to the current rendering settings for a layout.
void setDpi(double dpi)
Sets the dpi for outputting the layout.
double dpi() const
Returns the dpi for outputting the layout.
Stores information relating to the current reporting context for a layout.
An interface for layout objects which can be stored and read from DOM elements.
Provides a method of storing sizes, consisting of a width and height, for use in QGIS layouts.
Manages snapping grids and preset snap lines in a layout, and handles snapping points to the nearest ...
An undo stack for QgsLayouts.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
QgsLayoutItem * itemById(const QString &id) const
Returns a layout item given its id.
void removeMultiFrame(QgsLayoutMultiFrame *multiFrame)
Removes a multiFrame from the layout (but does not delete it).
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for the layout.
void updateBounds()
Updates the scene bounds of the layout.
bool saveAsTemplate(const QString &path, const QgsReadWriteContext &context) const
Saves the layout as a template at the given file path.
QgsAbstractLayoutUndoCommand * createCommand(const QString &text, int id=0, QUndoCommand *parent=nullptr) override
Creates a new layout undo command with the specified text and parent.
void initializeDefaults()
Initializes an empty layout, e.g.
QgsLayoutRenderContext & renderContext()
Returns a reference to the layout's render context, which stores information relating to the current ...
void removeCustomProperty(const QString &key)
Remove a custom property from the layout.
QgsLayoutModel * itemsModel()
Returns the items model attached to the layout.
QgsLayoutPageCollection * pageCollection()
Returns a pointer to the layout's page collection, which stores and manages page items in the layout.
void variablesChanged()
Emitted whenever the expression variables stored in the layout have been changed.
void layoutItems(QList< T * > &itemList) const
Returns a list of layout items of a specific type.
QgsLayoutItem * itemByUuid(const QString &uuid, bool includeTemplateUuids=false) const
Returns the layout item with matching uuid unique identifier, or nullptr if a matching item could not...
void addMultiFrame(QgsLayoutMultiFrame *multiFrame)
Adds a multiFrame to the layout.
void setUnits(Qgis::LayoutUnit units)
Sets the native measurement units for the layout.
QgsLayoutGuideCollection & guides()
Returns a reference to the layout's guide collection, which manages page snap guides.
QList< QgsLayoutItem * > ungroupItems(QgsLayoutItemGroup *group)
Ungroups items by removing them from an item group and removing the group from the layout.
bool moveItemToTop(QgsLayoutItem *item, bool deferUpdate=false)
Raises an item up to the top of the z-order.
QgsLayoutItem * layoutItemAt(QPointF position, bool ignoreLocked=false, double searchTolerance=0) const
Returns the topmost layout item at a specified position.
QgsLayoutItemMap * referenceMap() const
Returns the map item which will be used to generate corresponding world files when the layout is expo...
void changed()
Emitted when properties of the layout change.
friend class QgsLayoutMultiFrame
bool moveItemToBottom(QgsLayoutItem *item, bool deferUpdate=false)
Lowers an item down to the bottom of the z-order.
QgsLayoutItemGroup * groupItems(const QList< QgsLayoutItem * > &items)
Creates a new group from a list of layout items and adds the group to the layout.
QList< QgsLayoutItem * > addItemsFromXml(const QDomElement &parentElement, const QDomDocument &document, const QgsReadWriteContext &context, QPointF *position=nullptr, bool pasteInPlace=false)
Add items from an XML representation to the layout.
friend class QgsLayoutItemAddItemCommand
void reloadSettings()
Refreshes the layout when global layout related options change.
double convertToLayoutUnits(QgsLayoutMeasurement measurement) const
Converts a measurement into the layout's native units.
virtual bool readXml(const QDomElement &layoutElement, const QDomDocument &document, const QgsReadWriteContext &context)
Sets the collection's state from a DOM element.
QStringList customProperties() const
Returns list of keys stored in custom properties for the layout.
QgsLayout * clone() const
Creates a clone of the layout.
void clear()
Clears the layout.
QgsLayoutItem * itemByTemplateUuid(const QString &uuid) const
Returns the layout item with matching template uuid unique identifier, or nullptr if a matching item ...
friend class QgsLayoutUndoCommand
bool lowerItem(QgsLayoutItem *item, bool deferUpdate=false)
Lowers an item down the z-order.
QgsLayoutMeasurement convertFromLayoutUnits(double length, Qgis::LayoutUnit unit) const
Converts a length measurement from the layout's native units to a specified target unit.
friend class QgsLayoutModel
QList< QgsLayoutItem * > loadFromTemplate(const QDomDocument &document, const QgsReadWriteContext &context, bool clearExisting=true, bool *ok=nullptr)
Load a layout template document.
static const QgsSettingsEntryStringList * settingsSearchPathForTemplates
Settings entry search path for templates.
bool raiseItem(QgsLayoutItem *item, bool deferUpdate=false)
Raises an item up the z-order.
QList< QgsLayoutItem * > selectedLayoutItems(bool includeLockedItems=true)
Returns list of selected layout items.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from the layout.
void selectedItemChanged(QgsLayoutItem *selected)
Emitted whenever the selected item changes.
void deselectAll()
Clears any selected items in the layout.
void setSelectedItem(QgsLayoutItem *item)
Clears any selected items and sets item as the current selection.
QRectF layoutBounds(bool ignorePages=false, double margin=0.0) const
Calculates the bounds of all non-gui items in the layout.
void refresh()
Forces the layout, and all items contained within it, to refresh.
void backgroundTaskCountChanged(int total)
Emitted whenever the total number of background tasks running in items from the layout changes.
void removeLayoutItem(QgsLayoutItem *item)
Removes an item from the layout.
void refreshed()
Emitted when the layout has been refreshed and items should also be refreshed and updated.
void updateZValues(bool addUndoCommands=true)
Resets the z-values of items based on their position in the internal z order list.
QgsExpressionContext createExpressionContext() const override
Creates an expression context relating to the layout's current state.
QgsLayoutReportContext & reportContext()
Returns a reference to the layout's report context, which stores information relating to the current ...
virtual QDomElement writeXml(QDomDocument &document, const QgsReadWriteContext &context) const
Returns the layout's state encapsulated in a DOM element.
void setReferenceMap(QgsLayoutItemMap *map)
Sets the map item which will be used to generate corresponding world files when the layout is exporte...
QList< QgsLayoutMultiFrame * > multiFrames() const
Returns a list of multi frames contained in the layout.
void addLayoutItem(QgsLayoutItem *item)
Adds an item to the layout.
QgsLayoutMultiFrame * multiFrameByUuid(const QString &uuid, bool includeTemplateUuids=false) const
Returns the layout multiframe with matching uuid unique identifier, or nullptr if a matching multifra...
bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
QgsProject * project() const
The project associated with the layout.
void itemAdded(QgsLayoutItem *item)
Emitted when an item was added to the layout.
QRectF pageItemBounds(int page, bool visibleOnly=false) const
Returns the bounding box of the items contained on a specified page.
QgsLayout(QgsProject *project)
Construct a new layout linked to the specified project.
QgsLayoutUndoStack * undoStack()
Returns a pointer to the layout's undo stack, which manages undo/redo states for the layout and it's ...
void writeXml(QDomNode &parentNode, QDomDocument &doc) const
Writes the store contents to an XML node.
void readXml(const QDomNode &parentNode, const QString &keyStartsWith=QString())
Read store contents from an XML node.
Describes the version of a project.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
A container for the context for various read/write operations on objects.
A string list settings entry.
static QgsSettingsTreeNode * sTreeLayout
An interface for classes which can visit style entity (e.g.
Container for all settings relating to text rendering.
double lineHeight() const
Returns the line height for text.
Qgis::RenderUnit lineHeightUnit() const
Returns the units for the line height for text.
void setLineHeight(double height)
Sets the line height for text.
static Q_INVOKABLE Qgis::LayoutUnit decodeLayoutUnit(const QString &string, bool *ok=nullptr)
Decodes a layout unit from a string.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.