QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
32 createDefaultPageStyleSymbol();
37 const auto constMPages = mPages;
40 mLayout->removeItem(
page );
61 return mPageStyleSymbol.get();
66 mPreviousItemPositions.clear();
67 QList< QgsLayoutItem * > items;
75 mPreviousItemPositions.insert( item->uuid(), qMakePair( item->page(), item->pagePositionWithUnits() ) );
81 for (
auto it = mPreviousItemPositions.constBegin(); it != mPreviousItemPositions.constEnd(); ++it )
83 const QString key { it.key() };
86 if ( !mBlockUndoCommands )
87 item->beginCommand( QString() );
89 item->attemptMove( it.value().second,
true,
false, it.value().first );
94 if ( !mBlockUndoCommands )
99 item->cancelCommand();
103 mPreviousItemPositions.clear();
110 const auto constMPages = mPages;
139 double area = pageSize.width() * pageSize.height();
140 if ( area > maxArea )
155 if ( !size.isValid() )
160 || !
qgsDoubleNear( pageSize.height(), size.height(), 0.01 ) )
170 double startNextPageY = 0;
171 const auto constMPages = mPages;
175 if ( startNextPageY > point.y() )
187 if ( mPages.empty() )
191 double startNextPageY = 0;
192 const auto constMPages = mPages;
196 if ( startNextPageY >= point.y() )
201 if ( startNextPageY >= point.y() )
207 double lastPageHeight = mPages.last()->rect().height();
208 while ( startNextPageY < point.y() )
211 if ( startNextPageY >= point.y() )
221 const QList< QGraphicsItem * > items = mLayout->items( point );
222 for ( QGraphicsItem *item : items )
237 if (
page > 0 &&
page < mPages.count() )
239 layoutUnitsPos.ry() += mPages.at(
page )->pos().y();
241 return layoutUnitsPos;
247 if (
page > 0 &&
page < mPages.count() )
257 double startCurrentPageY = 0;
258 double startNextPageY = 0;
260 const auto constMPages = mPages;
263 startCurrentPageY = startNextPageY;
265 if ( startNextPageY > position.y() )
280 y = position.y() - startCurrentPageY;
282 return QPointF( position.x(), y );
299 if ( bounds.isEmpty() )
302 if ( !mBlockUndoCommands )
310 if ( mPages.empty() )
312 std::unique_ptr< QgsLayoutItemPage >
page = std::make_unique< QgsLayoutItemPage >( mLayout );
323 bounds.setWidth( bounds.width() + marginLeft + marginRight );
324 bounds.setHeight( bounds.height() + marginTop + marginBottom );
332 double diffX = marginLeft - bounds.left();
333 double diffY = marginTop - bounds.top();
335 const QList<QGraphicsItem *> itemList = mLayout->items();
336 for ( QGraphicsItem *item : itemList )
344 layoutItem->attemptMoveBy( diffX, diffY );
345 layoutItem->endCommand();
352 const QList< QgsLayoutGuide * > verticalGuides = mLayout->
guides().
guides( Qt::Vertical );
355 guide->setLayoutPosition( guide->layoutPosition() + diffX );
357 const QList< QgsLayoutGuide * > horizontalGuides = mLayout->
guides().
guides( Qt::Horizontal );
360 guide->setLayoutPosition( guide->layoutPosition() + diffY );
364 if ( !mBlockUndoCommands )
370 QDomElement element = document.createElement( QStringLiteral(
"PageCollection" ) );
373 element.appendChild( pageStyleElem );
380 mGuideCollection->writeXml( element, document, context );
382 parentElement.appendChild( element );
388 QDomElement element = e;
389 if ( element.nodeName() != QLatin1String(
"PageCollection" ) )
391 element = element.firstChildElement( QStringLiteral(
"PageCollection" ) );
394 if ( element.nodeName() != QLatin1String(
"PageCollection" ) )
399 mBlockUndoCommands =
true;
405 mLayout->removeItem(
page );
411 QDomElement pageStyleSymbolElem = element.firstChildElement( QStringLiteral(
"symbol" ) );
412 if ( !pageStyleSymbolElem.isNull() )
414 mPageStyleSymbol.reset( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( pageStyleSymbolElem, context ) );
417 QDomNodeList pageList = element.elementsByTagName( QStringLiteral(
"LayoutItem" ) );
418 for (
int i = 0; i < pageList.size(); ++i )
420 QDomElement pageElement = pageList.at( i ).toElement();
422 if ( mPageStyleSymbol )
426 mPages.append(
page.get() );
427 mLayout->addItem(
page.release() );
432 mGuideCollection->readXml( element, document, context );
434 mBlockUndoCommands =
false;
440 return *mGuideCollection;
445 return *mGuideCollection;
450 const auto constMPages = mPages;
469 return mPages.count();
484 return mPages.indexOf(
page );
489 QList<QgsLayoutItemPage *>
pages;
490 const auto constMPages = mPages;
503 const auto constMPages = mPages;
534 QList<QgsLayoutItem *> itemList;
535 const QList<QGraphicsItem *> graphicsItemList = mLayout->items();
536 itemList.reserve( graphicsItemList.size() );
537 for ( QGraphicsItem *graphicsItem : graphicsItemList )
542 itemList.push_back( item );
550 if (
page >= mPages.count() ||
page < 0 )
561 QList<QgsLayoutFrame *> frames;
565 if ( frame->hidePageIfEmpty() && frame->isEmpty() )
576 if ( !mBlockUndoCommands )
578 mPages.append(
page );
579 mLayout->addItem(
page );
581 if ( !mBlockUndoCommands )
587 if ( mPages.empty() )
591 std::unique_ptr< QgsLayoutItemPage > newPage = std::make_unique< QgsLayoutItemPage >( mLayout );
594 return mPages.at( mPages.count() - 1 );
599 if ( !mBlockUndoCommands )
605 if ( beforePage < 0 )
609 if ( beforePage >= mPages.count() )
611 mPages.append(
page );
615 mPages.insert( beforePage,
page );
617 mLayout->addItem(
page );
621 for (
auto it = mPreviousItemPositions.begin(); it != mPreviousItemPositions.end(); ++it )
623 if ( it.value().first < beforePage )
626 it.value().first = it.value().first + 1;
630 if ( ! mBlockUndoCommands )
639 if ( pageNumber < 0 || pageNumber >= mPages.count() )
642 if ( !mBlockUndoCommands )
650 mLayout->removeItem(
page );
655 for (
auto it = mPreviousItemPositions.begin(); it != mPreviousItemPositions.end(); ++it )
660 it.value().first = it.value().first - 1;
664 if ( ! mBlockUndoCommands )
673 if ( !mPages.contains(
page ) )
676 if ( !mBlockUndoCommands )
681 int pageIndex = mPages.indexOf(
page );
684 mPages.removeAll(
page );
688 mLayout->removeItem(
page );
692 for (
auto it = mPreviousItemPositions.begin(); it != mPreviousItemPositions.end(); ++it )
694 if ( it.value().first <= pageIndex )
697 it.value().first = it.value().first - 1;
701 if ( !mBlockUndoCommands )
710 if ( !mBlockUndoCommands )
715 for (
int i = mPages.count() - 1; i >= 0; --i )
718 mPages.takeAt( i )->deleteLater();
721 if ( !mBlockUndoCommands )
730 mPages.removeAll(
page );
734 void QgsLayoutPageCollection::createDefaultPageStyleSymbol()
736 QVariantMap properties;
737 properties.insert( QStringLiteral(
"color" ), QStringLiteral(
"white" ) );
738 properties.insert( QStringLiteral(
"style" ), QStringLiteral(
"solid" ) );
739 properties.insert( QStringLiteral(
"style_border" ), QStringLiteral(
"no" ) );
740 properties.insert( QStringLiteral(
"joinstyle" ), QStringLiteral(
"miter" ) );
double bottom() const
Returns the bottom margin.
bool shouldDrawItem() const
Returns whether the item should be drawn in the current context.
double maximumPageWidth() const
Returns the maximum width of pages in the collection.
QgsLayoutSize pageSize() const
Returns the size of the page.
double top() const
Returns the top margin.
void setPageStyleSymbol(QgsFillSymbol *symbol)
Sets the symbol to use for drawing pages in the collection.
Item representing the paper in a layout.
bool pageIsEmpty(int page) const
Returns whether a given page index is empty, ie, it contains no items except for the background paper...
The class is used as a container of context for various read/write operations on other objects.
QList< QgsLayoutGuide * > guides()
Returns a list of all guides contained in the collection.
void deletePage(int pageNumber)
Deletes a page from the collection.
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 layoutItems(QList< T * > &itemList) const
Returns a list of layout items of a specific type.
void beginCommand(const QString &commandText, UndoCommand command=UndoNone)
Starts new undo command for this item.
void endPageSizeChange()
Should be called after changing any page item sizes, and preceded by a call to beginPageSizeChange().
double length() const
Returns the length of the measurement.
void endMacro()
Ends a macro command.
virtual void finalizeRestoreFromXml()
Called after all pending items have been restored from XML.
double pageShadowWidth() const
Returns the size of the page shadow, in layout units.
double spaceBetweenPages() const
Returns the space between pages, in layout units.
LayoutUnit
Layout measurement units.
QRectF boundingRect() const override
void update()
Updates the position (and visibility) of all guide line items.
double y() const
Returns y coordinate of point.
void setPageSize(const QgsLayoutSize &size)
Sets the size of the page.
int pageNumber(QgsLayoutItemPage *page) const
Returns the page number for the specified page, or -1 if the page is not contained in the collection.
QgsUnitTypes::LayoutUnit units() const
Returns the native units for the layout.
QgsLayoutItemPage * pageAtPoint(QPointF point) const
Returns the page at a specified point (in layout coordinates).
int page() const
Returns the page the item is currently on, with the first page returning 0.
QgsLayoutPageCollection * pageCollection()
Returns a pointer to the layout's page collection, which stores and manages page items in the layout.
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
bool writeXml(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores the item state in a DOM element.
QgsLayoutItemPage * extendByNewPage()
Adds a new page to the end of the collection.
bool readXml(const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context)
Sets the item state from a DOM element.
void setPageStyleSymbol(QgsFillSymbol *symbol)
Sets the symbol to use for drawing the page background.
QRectF layoutBounds(bool ignorePages=false, double margin=0.0) const
Calculates the bounds of all non-gui items in the layout.
int pageNumberForPoint(QPointF point) const
Returns the page number corresponding to a point in the layout (in layout units).
double left() const
Returns the left margin.
QPointF positionOnPage(QPointF point) const
Returns the position within a page of a point in the layout (in layout units).
void setY(const double y)
Sets y coordinate of point.
Base class for frame items, which form a layout multiframe item.
const Q_DECL_DEPRECATED QgsFillSymbol * pageStyleSymbol() const
Returns the symbol to use for drawing pages in the collection.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QList< int > visiblePageNumbers(const QRectF ®ion) const
Returns a list of the page numbers which are visible within the specified region (in layout coordinat...
void insertPage(QgsLayoutItemPage *page, int beforePage)
Inserts a page into a specific position in the collection.
void beginPageSizeChange()
Should be called before changing any page item sizes, and followed by a call to endPageSizeChange().
QList< QgsLayoutItemPage * > pages()
Returns a list of pages in the collection.
void changed()
Emitted when pages are added or removed from the collection.
The QgsMargins class defines the four margins of a rectangle.
void updateBounds()
Updates the scene bounds of the layout.
double right() const
Returns the right margin.
QgsLayoutItemPage * page(int pageNumber)
Returns a specific page (by pageNumber) from the collection.
int predictPageNumberForPoint(QPointF point) const
Returns the theoretical page number corresponding to a point in the layout (in layout units),...
Base class for graphical items within a QgsLayout.
Contains the configuration for a single snap guide used by a layout.
static QgsFillSymbol * createSimple(const QVariantMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
QgsLayoutGuideCollection & guides()
Returns a reference to the collection's guide collection, which manages page snap guides.
void beginMacro(const QString &commandText)
Starts a macro command, with the given descriptive commandText.
QList< QgsLayoutItemPage * > visiblePages(const QRectF ®ion) const
Returns a list of the pages which are visible within the specified region (in layout coordinates).
Stores and manages the snap guides used by a layout.
virtual void attemptMove(const QgsLayoutPoint &point, bool useReferencePoint=true, bool includesFrame=false, int page=-1)
Attempts to move the item to a specified point.
QgsLayout * layout() override
Returns the layout the object belongs to.
void addPage(QgsLayoutItemPage *page)
Adds a page to the collection.
void endCommand()
Saves final state of an object and pushes the active command to the undo history.
void redraw()
Triggers a redraw for all pages.
QgsLayoutPageCollection(QgsLayout *layout)
Constructor for QgsLayoutItemPage, with the specified parent layout.
void reflow()
Forces the page collection to reflow the arrangement of pages, e.g.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
QgsLayoutPoint pagePositionToAbsolute(int page, const QgsLayoutPoint &position) const
Converts a position on a page to an absolute position in (maintaining the units from the input positi...
QgsFillSymbol * clone() const override
Returns a deep copy of this symbol.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
bool readXml(const QDomElement &collectionElement, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets the collection's state from a DOM element.
void beginCommand(QgsLayoutUndoObjectInterface *object, const QString &commandText, int id=0)
Begins a new undo command for the specified object.
void pageAboutToBeRemoved(int pageNumber)
Emitted just before a page is removed from the collection.
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
QgsLayoutGuideCollection & guides()
Returns a reference to the layout's guide collection, which manages page snap guides.
QSizeF maximumPageSize() const
Returns the maximum size of any page in the collection, by area.
bool writeXml(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores the collection's state in a DOM element.
~QgsLayoutPageCollection() override
bool shouldExportPage(int page) const
Returns whether the specified page number should be included in exports of the layouts.
int pageCount() const
Returns the number of pages in the collection.
This class provides a method of storing points, consisting of an x and y coordinate,...
QList< QgsLayoutItem * > itemsOnPage(int page) const
Returns a list of layout items on the specified page index.
void clear()
Removes all pages from the collection.
double convertToLayoutUnits(QgsLayoutMeasurement measurement) const
Converts a measurement into the layout's native units.
double x() const
Returns x coordinate of point.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
QgsLayoutMeasurement convertFromLayoutUnits(double length, QgsUnitTypes::LayoutUnit unit) const
Converts a length measurement from the layout's native units to a specified target unit.
QPointF pagePositionToLayoutPosition(int page, const QgsLayoutPoint &position) const
Converts a position on a page to an absolute position in layout coordinates.
QgsUnitTypes::LayoutUnit units() const
Returns the units for the point.
bool hasUniformPageSizes() const
Returns true if the layout has uniform page sizes, e.g.
QgsLayoutItemPage * takePage(QgsLayoutItemPage *page)
Takes a page from the collection, returning ownership of the page to the caller.
void resizeToContents(const QgsMargins &margins, QgsUnitTypes::LayoutUnit marginUnits)
Resizes the layout to a single page which fits the current contents of the layout.
QgsLayoutUndoStack * undoStack()
Returns a pointer to the layout's undo stack, which manages undo/redo states for the layout and it's ...