48#include "moc_qgslayout.cpp"
50using namespace Qt::StringLiterals;
59 , mGridSettings( this )
64 setBackgroundBrush( Qt::NoBrush );
65 mItemsModel = std::make_unique<QgsLayoutModel>(
this );
71 mUndoStack->blockCommands(
true );
73 deleteAndRemoveMultiFrames();
81 QList<QGraphicsItem *> itemList = items();
86 for ( QGraphicsItem *item : std::as_const( itemList ) )
103 QDomDocument currentDoc;
106 QDomElement elem =
writeXml( currentDoc, context );
107 currentDoc.appendChild( elem );
109 auto newLayout = std::make_unique< QgsLayout >( mProject );
111 newLayout->loadFromTemplate( currentDoc, context,
true, &ok );
117 return newLayout.release();
125 mPageCollection->addPage( page );
126 mUndoStack->stack()->clear();
131 deleteAndRemoveMultiFrames();
134 const QList<QGraphicsItem *> itemList = items();
135 for ( QGraphicsItem *item : itemList )
139 if ( cItem && !pItem )
141 removeLayoutItemPrivate( cItem );
144 mItemsModel->clear();
146 mPageCollection->clear();
147 mUndoStack->stack()->clear();
157 return mItemsModel.get();
162 QList<QgsLayoutItem *> layoutItemList;
164 const QList<QGraphicsItem *> graphicsItemList = selectedItems();
165 for ( QGraphicsItem *item : graphicsItemList )
168 if ( layoutItem && ( includeLockedItems || !layoutItem->
isLocked() ) )
170 layoutItemList.push_back( layoutItem );
174 return layoutItemList;
193 const QList<QGraphicsItem *> selectedItemList = selectedItems();
194 for ( QGraphicsItem *item : selectedItemList )
198 layoutItem->setSelected(
false );
207 bool result = mItemsModel->reorderItemUp( item );
208 if ( result && !deferUpdate )
220 bool result = mItemsModel->reorderItemDown( item );
221 if ( result && !deferUpdate )
233 bool result = mItemsModel->reorderItemToTop( item );
234 if ( result && !deferUpdate )
246 bool result = mItemsModel->reorderItemToBottom( item );
247 if ( result && !deferUpdate )
258 QList<QgsLayoutItem *> itemList;
262 if ( item->uuid() == uuid )
264 else if ( includeTemplateUuids && item->mTemplateUuid == uuid )
273 QList<QgsLayoutItem *> itemList;
277 if ( item->mTemplateUuid == uuid )
286 const QList<QGraphicsItem *> itemList = items();
287 for ( QGraphicsItem *item : itemList )
290 if ( layoutItem && layoutItem->
id() ==
id )
302 if ( mf->uuid() == uuid )
304 else if ( includeTemplateUuids && mf->mTemplateUuid == uuid )
313 return layoutItemAt( position,
nullptr, ignoreLocked, searchTolerance );
319 QList<QGraphicsItem *> itemList;
320 if ( searchTolerance == 0 )
322 itemList = items( position, Qt::IntersectsItemShape, Qt::DescendingOrder );
326 itemList = items( QRectF( position.x() - searchTolerance, position.y() - searchTolerance, 2 * searchTolerance, 2 * searchTolerance ), Qt::IntersectsItemShape, Qt::DescendingOrder );
329 bool foundBelowItem =
false;
330 for ( QGraphicsItem *graphicsItem : std::as_const( itemList ) )
334 if ( layoutItem && !paperItem )
338 if ( ( ! belowItem || foundBelowItem ) && ( !ignoreLocked || !layoutItem->
isLocked() ) )
343 return layoutItemAt( position, layoutItem, ignoreLocked, searchTolerance );
350 if ( layoutItem == belowItem )
353 foundBelowItem =
true;
363 return mRenderContext->measurementConverter().convert( measurement, mUnits ).length();
368 return mRenderContext->measurementConverter().convert( size, mUnits ).toQSizeF();
373 return mRenderContext->measurementConverter().convert( point, mUnits ).toQPointF();
378 return mRenderContext->measurementConverter().convert(
QgsLayoutMeasurement( length, mUnits ), unit );
383 return mRenderContext->measurementConverter().convert(
QgsLayoutSize( size.width(), size.height(), mUnits ), unit );
388 return mRenderContext->measurementConverter().convert(
QgsLayoutPoint( point.x(), point.y(), mUnits ), unit );
393 return *mRenderContext;
398 return *mRenderContext;
403 return *mReportContext;
408 return *mReportContext;
413 mGridSettings.loadFromSettings();
414 mPageCollection->redraw();
419 return mPageCollection->
guides();
424 return mPageCollection->
guides();
432 if ( mReportContext->layer() )
441 mCustomProperties.setValue( key, value );
443 if ( key.startsWith(
"variable"_L1 ) )
449 return mCustomProperties.value( key, defaultValue );
454 mCustomProperties.remove( key );
459 return mCustomProperties.keys();
469 QList< QgsLayoutItemMap * > maps;
472 double largestMapArea = 0;
475 double area = map->rect().width() * map->rect().height();
476 if ( area > largestMapArea )
478 largestMapArea = area;
487 mWorldFileMapId = map ? map->
uuid() : QString();
488 mProject->setDirty(
true );
493 return mPageCollection.get();
498 return mPageCollection.get();
507 const auto constItems = items();
508 for (
const QGraphicsItem *item : constItems )
515 if ( !isPage || !ignorePages )
523 itemBounds = layoutItem->mapToScene( layoutItem->rect() ).boundingRect();
526 itemBounds = item->sceneBoundingRect();
528 if ( bounds.isValid() )
529 bounds = bounds.united( itemBounds );
535 if ( bounds.isValid() && margin > 0.0 )
538 double maxWidth = mPageCollection->maximumPageWidth();
539 bounds.adjust( -maxWidth * margin, -maxWidth * margin, maxWidth * margin, maxWidth * margin );
552 const QList<QGraphicsItem *> itemList = items();
553 for ( QGraphicsItem *item : itemList )
558 if ( visibleOnly && !layoutItem->isVisible() )
562 if ( bounds.isValid() )
563 bounds = bounds.united( item->sceneBoundingRect() );
565 bounds = item->sceneBoundingRect();
574 addLayoutItemPrivate( item );
578 undoText = tr(
"Create %1" ).arg( metadata->visibleName() );
582 undoText = tr(
"Create Item" );
584 if ( !mUndoStack->isBlocked() )
590 std::unique_ptr< QgsLayoutItemDeleteUndoCommand > deleteCommand;
591 if ( !mUndoStack->isBlocked() )
593 mUndoStack->beginMacro( tr(
"Delete Items" ) );
594 deleteCommand = std::make_unique<QgsLayoutItemDeleteUndoCommand>( item, tr(
"Delete Item" ) );
596 removeLayoutItemPrivate( item );
599 mUndoStack->push( deleteCommand.release() );
600 mUndoStack->endMacro();
609 if ( !mMultiFrames.contains( multiFrame ) )
610 mMultiFrames << multiFrame;
615 mMultiFrames.removeAll( multiFrame );
625 QFile templateFile( path );
626 if ( !templateFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
631 QDomDocument saveDocument;
632 QDomElement elem =
writeXml( saveDocument, context );
633 saveDocument.appendChild( elem );
635 if ( templateFile.write( saveDocument.toByteArray() ) == -1 )
646 QList< QgsLayoutItem * > result;
666 QDomNodeList itemsNodes = doc.elementsByTagName( u
"LayoutItem"_s );
667 for (
int i = 0; i < itemsNodes.count(); ++i )
669 QDomNode itemNode = itemsNodes.at( i );
670 if ( itemNode.isElement() )
672 itemNode.toElement().removeAttribute( u
"uuid"_s );
675 QDomNodeList multiFrameNodes = doc.elementsByTagName( u
"LayoutMultiFrame"_s );
676 for (
int i = 0; i < multiFrameNodes.count(); ++i )
678 QDomNode multiFrameNode = multiFrameNodes.at( i );
679 if ( multiFrameNode.isElement() )
681 multiFrameNode.toElement().removeAttribute( u
"uuid"_s );
682 QDomNodeList frameNodes = multiFrameNode.toElement().elementsByTagName( u
"childFrame"_s );
683 QDomNode itemNode = frameNodes.at( i );
684 if ( itemNode.isElement() )
686 itemNode.toElement().removeAttribute( u
"uuid"_s );
694 QDomElement layoutElem = doc.documentElement();
695 if ( layoutElem.isNull() )
700 bool loadOk =
readXml( layoutElem, doc, context );
720 return mUndoStack.get();
725 return mUndoStack.get();
740 void saveState( QDomDocument &stateDoc )
const override
743 QDomElement documentElement = stateDoc.createElement( u
"UndoState"_s );
744 mLayout->writeXmlLayoutSettings( documentElement, stateDoc, QgsReadWriteContext() );
745 stateDoc.appendChild( documentElement );
755 mLayout->readXmlLayoutSettings( stateDoc.documentElement(), stateDoc, QgsReadWriteContext() );
756 mLayout->project()->setDirty(
true );
761 QgsLayout *mLayout =
nullptr;
772 if ( items.size() < 2 )
778 mUndoStack->beginMacro( tr(
"Group Items" ) );
779 auto itemGroup = std::make_unique<QgsLayoutItemGroup>(
this );
782 itemGroup->addItem( item );
787 auto c = std::make_unique<QgsLayoutItemGroupUndoCommand>( QgsLayoutItemGroupUndoCommand::Grouped, returnGroup,
this, tr(
"Group Items" ) );
788 mUndoStack->push(
c.release() );
789 mProject->setDirty(
true );
791 mUndoStack->endMacro();
799 QList<QgsLayoutItem *> ungroupedItems;
802 return ungroupedItems;
805 mUndoStack->beginMacro( tr(
"Ungroup Items" ) );
808 auto c = std::make_unique<QgsLayoutItemGroupUndoCommand>( QgsLayoutItemGroupUndoCommand::Ungrouped, group,
this, tr(
"Ungroup Items" ) );
809 mUndoStack->push(
c.release() );
811 mProject->setDirty(
true );
813 ungroupedItems = group->
items();
817 mUndoStack->endMacro();
819 return ungroupedItems;
824 const QList< QGraphicsItem * > constItems = items();
825 for (
const QGraphicsItem *item : constItems )
831 if ( !layoutItem->
accept( visitor ) )
839 mUndoStack->blockCommands(
true );
840 mPageCollection->beginPageSizeChange();
842 mPageCollection->reflow();
843 mPageCollection->endPageSizeChange();
844 mUndoStack->blockCommands(
false );
848void QgsLayout::writeXmlLayoutSettings( QDomElement &element, QDomDocument &document,
const QgsReadWriteContext & )
const
850 mCustomProperties.
writeXml( element, document );
852 element.setAttribute( u
"worldFileMap"_s, mWorldFileMapId );
853 element.setAttribute( u
"printResolution"_s, mRenderContext->
dpi() );
858 QDomElement element = document.createElement( u
"Layout"_s );
861 return object->writeXml( element, document, context );
864 save( &mGridSettings );
865 save( mPageCollection.get() );
868 const QList<QGraphicsItem *> itemList = items();
869 for (
const QGraphicsItem *graphicsItem : itemList )
876 item->writeXml( element, document, context );
883 if ( mf->frameCount() > 0 )
884 mf->writeXml( element, document, context );
887 writeXmlLayoutSettings( element, document, context );
891bool QgsLayout::readXmlLayoutSettings(
const QDomElement &layoutElement,
const QDomDocument &,
const QgsReadWriteContext & )
893 mCustomProperties.
readXml( layoutElement );
895 mWorldFileMapId = layoutElement.attribute( u
"worldFileMap"_s );
896 mRenderContext->
setDpi( layoutElement.attribute( u
"printResolution"_s, u
"300"_s ).toDouble() );
906 mItemsModel->rebuildZList();
911void QgsLayout::removeLayoutItemPrivate(
QgsLayoutItem *item )
913 mItemsModel->setItemRemoved( item );
920 emit itemRemoved( item );
926void QgsLayout::deleteAndRemoveMultiFrames()
928 qDeleteAll( mMultiFrames );
929 mMultiFrames.clear();
932QPointF QgsLayout::minPointFromXml(
const QDomElement &elem )
const
934 double minX = std::numeric_limits<double>::max();
935 double minY = std::numeric_limits<double>::max();
936 const QDomNodeList itemList = elem.elementsByTagName( u
"LayoutItem"_s );
938 for (
int i = 0; i < itemList.size(); ++i )
940 const QDomElement currentItemElem = itemList.at( i ).toElement();
945 minX = std::min( minX, layoutPoint.x() );
946 minY = std::min( minY, layoutPoint.y() );
949 return found ? QPointF( minX, minY ) : QPointF( 0, 0 );
954 int counter = mItemsModel->zOrderListSize();
955 const QList<QgsLayoutItem *> zOrderList = mItemsModel->zOrderList();
957 if ( addUndoCommands )
959 mUndoStack->beginMacro( tr(
"Change Item Stacking" ) );
965 if ( addUndoCommands )
967 mUndoStack->beginCommand( currentItem, QString() );
969 currentItem->setZValue( counter );
970 if ( addUndoCommands )
972 mUndoStack->endCommand();
977 if ( addUndoCommands )
979 mUndoStack->endMacro();
985 if ( layoutElement.nodeName() !=
"Layout"_L1 )
992 return object->readXml( layoutElement, document, context );
995 std::unique_ptr< QgsScopedRuntimeProfile > profile;
997 profile = std::make_unique< QgsScopedRuntimeProfile >( tr(
"Read layout settings" ), u
"projectload"_s );
999 blockSignals(
true );
1000 readXmlLayoutSettings( layoutElement, document, context );
1001 blockSignals(
false );
1004 profile->switchTask( tr(
"Load pages" ) );
1005 restore( mPageCollection.get() );
1007 profile->switchTask( tr(
"Load snapping settings" ) );
1008 restore( &mSnapper );
1010 profile->switchTask( tr(
"Load grid settings" ) );
1011 restore( &mGridSettings );
1014 profile->switchTask( tr(
"Restore items" ) );
1024 QList< QgsLayoutItem * > newItems;
1025 QList< QgsLayoutMultiFrame * > newMultiFrames;
1030 int zOrderOffset = mItemsModel->zOrderListSize();
1032 QPointF pasteShiftPos;
1033 int pageNumber = -1;
1039 QPointF minItemPos = minPointFromXml( parentElement );
1042 pasteShiftPos = *position - minItemPos;
1045 pageNumber = mPageCollection->pageNumberForPoint( *position );
1049 std::unique_ptr< QgsScopedRuntimeProfile > profile;
1051 profile = std::make_unique< QgsScopedRuntimeProfile >( tr(
"Read items" ), u
"projectload"_s );
1056 const QDomNodeList multiFrameList = parentElement.elementsByTagName( u
"LayoutMultiFrame"_s );
1057 for (
int i = 0; i < multiFrameList.size(); ++i )
1059 const QDomElement multiFrameElem = multiFrameList.at( i ).toElement();
1060 const int itemType = multiFrameElem.attribute( u
"type"_s ).toInt();
1066 profile->switchTask( tr(
"Load %1" ).arg( metadata->visibleName() ) );
1076 mf->readXml( multiFrameElem, document, context );
1079 mf->setCreateUndoCommands(
true );
1094 newMultiFrames << m;
1097 const QDomNodeList layoutItemList = parentElement.childNodes();
1098 for (
int i = 0; i < layoutItemList.size(); ++i )
1100 const QDomElement currentItemElem = layoutItemList.at( i ).toElement();
1101 if ( currentItemElem.nodeName() !=
"LayoutItem"_L1 )
1104 const int itemType = currentItemElem.attribute( u
"type"_s ).toInt();
1110 profile->switchTask( tr(
"Load %1" ).arg( metadata->visibleName() ) );
1121 item->readXml( currentItemElem, document, context );
1127 item->attemptMove( posOnPage,
true,
false, pageNumber );
1131 item->attemptMoveBy( pasteShiftPos.x(), pasteShiftPos.y() );
1147 label->setTextFormat( textFormat );
1151 if ( item->isGroupMember() )
1155 QList<QgsLayoutItem *>
groupItems = group->items();
1157 group->removeItems();
1160 group->addItem( groupItem );
1162 group->addItem( html->
frame( 0 ) );
1165 newMultiFrames << html;
1173 layoutItem->setZValue( layoutItem->zValue() + zOrderOffset );
1174 newItems << layoutItem;
1181 std::unique_ptr< QgsScopedRuntimeProfile > itemProfile;
1184 profile->switchTask( tr(
"Finalize restore" ) );
1189 itemProfile = std::make_unique< QgsScopedRuntimeProfile >( item->
displayName(), u
"projectload"_s );
1192 itemProfile.reset();
1197 itemProfile = std::make_unique< QgsScopedRuntimeProfile >( mf->displayName(), u
"projectload"_s );
1198 mf->finalizeRestoreFromXml();
1200 itemProfile.reset();
1205 item->mTemplateUuid.clear();
1209 mf->mTemplateUuid.clear();
1217 profile->switchTask( tr(
"Update model" ) );
1218 mItemsModel->rebuildZList();
1228void QgsLayout::itemBackgroundTaskCountChanged(
int count )
1230 QgsLayoutItem *item = qobject_cast<QgsLayoutItem *>( sender() );
1235 mBackgroundTaskCount.insert( item, count );
1237 mBackgroundTaskCount.remove( item );
1241 for (
auto it = mBackgroundTaskCount.constBegin(); it != mBackgroundTaskCount.constEnd(); ++it )
1243 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.