QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
27 , mUuid( QUuid::createUuid().toString() )
42 return QSizeF( 0, 0 );
48 return QSizeF( 0, 0 );
62 frame->mMultiFrame =
this;
64 connect(
frame, &QgsLayoutFrame::destroyed,
this, [
this,
frame ]
66 handleFrameRemoval(
frame );
73 if ( recalcFrameSizes )
83 mLayout->undoStack()->beginMacro( tr(
"Change Resize Mode" ) );
86 mLayout->undoStack()->endMacro();
104 double totalHeight = size.height();
106 if ( totalHeight < 1 )
111 if ( mBlockUndoCommands )
112 mLayout->undoStack()->blockCommands(
true );
115 double currentHeight = 0;
124 bool removingPages =
true;
127 int numPagesBefore =
mLayout->pageCollection()->pageCount();
130 removingPages = removingPages && (
mLayout->pageCollection()->pageCount() < numPagesBefore );
137 currentHeight = currentItem->rect().height();
140 currentItem->
setContentSection( QRectF( 0, 0, currentItem->rect().width(), currentHeight ) );
145 currentItem->
setContentSection( QRectF( 0, currentY, currentItem->rect().width(), currentHeight ) );
147 currentItem->update();
148 currentY += currentHeight;
157 int page =
mLayout->pageCollection()->predictPageNumberForPoint( QPointF( 0, currentItem->pos().y() + currentItem->rect().height() ) ) + 1;
161 if ( page >=
mLayout->pageCollection()->pageCount() )
169 for (
int p =
mLayout->pageCollection()->pageCount() - 1 ; p < page; ++p )
171 mLayout->pageCollection()->extendByNewPage();
175 double currentPageHeight =
mLayout->pageCollection()->page( page )->rect().height();
177 double frameHeight = 0;
183 frameHeight = currentItem->rect().height();
188 frameHeight = ( currentY + currentPageHeight ) > totalHeight ? totalHeight - currentY : currentPageHeight;
196 double newFrameY =
mLayout->pageCollection()->page( page )->pos().y();
199 newFrameY += currentItem->
pagePos().y();
204 QPointF( currentItem->pos().x(), newFrameY ),
205 QSizeF( currentItem->rect().width(), frameHeight ) );
209 newFrame->
setContentSection( QRectF( 0, 0, newFrame->rect().width(), newFrame->rect().height() ) );
210 currentY += frameHeight;
214 double contentHeight =
findNearbyPageBreak( currentY + newFrame->rect().height() ) - currentY;
215 newFrame->
setContentSection( QRectF( 0, currentY, newFrame->rect().width(), contentHeight ) );
216 currentY += contentHeight;
219 currentItem = newFrame;
223 if ( mBlockUndoCommands )
224 mLayout->undoStack()->blockCommands(
false );
275 return tr(
"<Multiframe>" );
280 return new QgsLayoutMultiFrameUndoCommand(
this, text,
id, parent );
295 mLayout->undoStack()->beginCommand(
this, commandText, command );
301 mLayout->undoStack()->endCommand();
307 mLayout->undoStack()->cancelCommand();
312 for (
int i = 0; i < mFrameUuids.count(); ++i )
315 const QString
uuid = mFrameUuids.at( i );
316 if ( !
uuid.isEmpty() )
319 frame = qobject_cast< QgsLayoutFrame * >( item );
323 const QString templateUuid = mFrameTemplateUuids.at( i );
324 if ( !templateUuid.isEmpty() )
327 frame = qobject_cast< QgsLayoutFrame * >( item );
344 void QgsLayoutMultiFrame::handleFrameRemoval(
QgsLayoutFrame *frame )
373 void QgsLayoutMultiFrame::handlePageChange()
375 if (
mLayout->pageCollection()->pageCount() < 1 )
386 for (
int i =
mFrameItems.size() - 1; i >= 0; --i )
389 int page =
mLayout->pageCollection()->predictPageNumberForPoint(
frame->pos() );
390 if ( page >=
mLayout->pageCollection()->pageCount() )
400 int lastItemPage =
mLayout->pageCollection()->predictPageNumberForPoint( lastFrame->pos() );
402 for (
int i = lastItemPage + 1; i <
mLayout->pageCollection()->pageCount(); ++i )
405 std::unique_ptr< QgsLayoutFrame > newFrame = qgis::make_unique< QgsLayoutFrame >(
mLayout,
this );
407 newFrame->attemptSetSceneRect( QRectF( lastFrame->pos().x(),
408 mLayout->pageCollection()->page( i )->pos().y() + lastFrame->
pagePos().y(),
409 lastFrame->rect().width(), lastFrame->rect().height() ) );
410 lastFrame = newFrame.get();
411 addFrame( newFrame.release(),
false );
429 mIsRecalculatingSize =
true;
430 int pageNumber = frameItem->
page();
432 mLayout->undoStack()->blockCommands(
true );
433 mLayout->removeLayoutItem( frameItem );
435 if ( removeEmptyPages &&
mLayout->pageCollection()->pageIsEmpty( pageNumber ) )
437 mLayout->pageCollection()->deletePage( pageNumber );
439 mLayout->undoStack()->blockCommands(
false );
440 mIsRecalculatingSize =
false;
455 mBlockUpdates =
true;
458 mLayout->undoStack()->blockCommands(
true );
463 mLayout->undoStack()->blockCommands(
false );
466 mBlockUpdates =
false;
485 QDomElement element = doc.createElement( QStringLiteral(
"LayoutMultiFrame" ) );
486 element.setAttribute( QStringLiteral(
"resizeMode" ),
mResizeMode );
487 element.setAttribute( QStringLiteral(
"uuid" ), mUuid );
488 element.setAttribute( QStringLiteral(
"templateUuid" ), mUuid );
489 element.setAttribute( QStringLiteral(
"type" ),
type() );
496 QDomElement childItem = doc.createElement( QStringLiteral(
"childFrame" ) );
497 childItem.setAttribute( QStringLiteral(
"uuid" ),
frame->
uuid() );
498 childItem.setAttribute( QStringLiteral(
"templateUuid" ),
frame->
uuid() );
505 element.appendChild( childItem );
510 parentElement.appendChild( element );
516 if ( element.nodeName() != QLatin1String(
"LayoutMultiFrame" ) )
521 mBlockUndoCommands =
true;
522 mLayout->undoStack()->blockCommands(
true );
526 mUuid = element.attribute( QStringLiteral(
"uuid" ), QUuid::createUuid().toString() );
527 mTemplateUuid = element.attribute( QStringLiteral(
"templateUuid" ), QUuid::createUuid().toString() );
528 mResizeMode =
static_cast< ResizeMode >( element.attribute( QStringLiteral(
"resizeMode" ), QStringLiteral(
"0" ) ).toInt() );
532 mFrameTemplateUuids.clear();
533 QDomNodeList elementNodes = element.elementsByTagName( QStringLiteral(
"childFrame" ) );
534 for (
int i = 0; i < elementNodes.count(); ++i )
536 QDomNode elementNode = elementNodes.at( i );
537 if ( !elementNode.isElement() )
540 QDomElement frameElement = elementNode.toElement();
542 QString
uuid = frameElement.attribute( QStringLiteral(
"uuid" ) );
544 QString templateUuid = frameElement.attribute( QStringLiteral(
"templateUuid" ) );
545 mFrameTemplateUuids << templateUuid;
549 QDomNodeList frameNodes = frameElement.elementsByTagName( QStringLiteral(
"LayoutItem" ) );
550 if ( !frameNodes.isEmpty() )
552 QDomElement frameItemElement = frameNodes.at( 0 ).toElement();
553 std::unique_ptr< QgsLayoutFrame > newFrame = qgis::make_unique< QgsLayoutFrame >(
mLayout,
this );
554 newFrame->readXml( frameItemElement, doc, context );
555 addFrame( newFrame.release(),
false );
562 mBlockUndoCommands =
false;
563 mLayout->undoStack()->blockCommands(
false );
QgsLayoutFrame * frame(int index) const
Returns the child frame at a specified index from the multiframe.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
double itemOpacity() const
Returns the item's opacity.
virtual QSizeF totalSize() const =0
Returns the total size of the multiframe's content, in layout units.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
virtual double findNearbyPageBreak(double yPos)
Finds the optimal position to break a frame at.
void endCommand()
Completes the current item command and push it onto the layout's undo stack.
bool writeXml(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context, bool includeFrames=false) const
Stores the multiframe state in a DOM element.
void refreshItemSize()
Refreshes an item's size by rechecking it against any possible item fixed or minimum sizes.
~QgsLayoutMultiFrame() override
void sizePositionChanged()
Emitted when the item's size or position changes.
virtual void refresh()
Refreshes the object, causing a recalculation of any property overrides.
virtual void setFrameEnabled(bool drawFrame)
Sets whether this item has a frame drawn around it or not.
bool frameEnabled() const
Returns true if the item includes a frame.
The class is used as a container of context for various read/write operations on other objects.
void setHideBackgroundIfEmpty(bool hideBackgroundIfEmpty)
Sets whether the background and frame stroke should be hidden if this frame is empty.
virtual void setFrameStrokeWidth(QgsLayoutMeasurement width)
Sets the frame stroke width.
virtual void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::AllProperties)
Refreshes a data defined property for the multi frame by reevaluating the property's value and redraw...
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 finalizeRestoreFromXml()
Called after all pending items have been restored from XML.
void removeFrame(int index, bool removeEmptyPages=false)
Removes a frame by index from the multiframe.
int page() const
Returns the page the item is currently on, with the first page returning 0.
static QgsExpressionContextScope * multiFrameScope(const QgsLayoutMultiFrame *frame)
Creates a new scope which contains variables and functions relating to a QgsLayoutMultiFrame.
bool hideBackgroundIfEmpty() const
Returns whether the background and frame stroke should be hidden if this frame is empty.
void changed()
Emitted when the object's properties change.
bool writeXml(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores the item state in a DOM element.
bool readXml(const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context, bool includeFrames=false)
Sets the item state from a DOM element.
@ ExtendToNextPage
Creates new full page frames on the following page(s) until the entire multiframe content is visible.
QList< QgsLayoutFrame * > mFrameItems
bool hasBackground() const
Returns true if the item has a background.
QgsLayoutMultiFrame(QgsLayout *layout)
Construct a new multiframe item, attached to the specified layout.
virtual int type() const =0
Returns unique multiframe type id.
void setBlendMode(QPainter::CompositionMode mode)
Sets the item's composition blending mode.
void update()
Forces a redraw of all child frames.
QColor backgroundColor() const
Returns the background color for this item.
QgsLayoutMeasurement frameStrokeWidth() const
Returns the frame's stroke width.
void cancelCommand()
Cancels the current item command and discards it.
Base class for frame items, which form a layout multiframe item.
Qt::PenJoinStyle frameJoinStyle() const
Returns the join style used for drawing the item's frame.
void setContentSection(const QRectF §ion)
Sets the visible part of the multiframe's content which is visible within this frame (relative to the...
void setBackgroundColor(const QColor &color)
Sets the background color for this item.
void setBackgroundEnabled(bool drawBackground)
Sets whether this item has a background drawn under it or not.
void changed()
Emitted when pages are added or removed from the collection.
ResizeMode
Specifies the behavior for creating new frames to fit the multiframe's content.
QgsAbstractLayoutUndoCommand * createCommand(const QString &text, int id, QUndoCommand *parent=nullptr) override
Creates a new layout undo command with the specified text and parent.
void setFrameStrokeColor(const QColor &color)
Sets the frame stroke color.
virtual bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores multiframe state within an XML DOM element.
void setFrameJoinStyle(Qt::PenJoinStyle style)
Sets the join style used when drawing the item's frame.
virtual QSizeF minFrameSize(int frameIndex=-1) const
Returns the minimum size for a frames, if desired.
ResizeMode resizeMode() const
Returns the resize mode for the multiframe.
Base class for graphical items within a QgsLayout.
void recalculateFrameRects()
Forces a recalculation of all the associated frame's scene rectangles.
QList< QgsLayoutFrame * > frames() const
Returns a list of all child frames for this multiframe.
void refresh() override
Refreshes the multiframe, causing a recalculation of any property overrides.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
QgsExpressionContext createExpressionContext() const override
Creates an expression context relating to the objects' current state.
void beginCommand(const QString &commandText, UndoCommand command=UndoNone)
Starts new undo command for this item.
QString uuid() const
Returns the multiframe identification string.
QPainter::CompositionMode blendMode() const
Returns the item's composition blending mode.
virtual QString uuid() const
Returns the item identification string.
bool readObjectPropertiesFromElement(const QDomElement &parentElement, const QDomDocument &document, const QgsReadWriteContext &context)
Sets object properties from a DOM element.
Base class for commands to undo/redo layout and layout object changes.
QPointer< QgsLayout > mLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
@ RepeatOnEveryPage
Repeats the same frame on every page.
virtual QSizeF fixedFrameSize(int frameIndex=-1) const
Returns the fixed size for a frame, if desired.
UndoCommand
Multiframe item undo commands, used for collapsing undo commands.
virtual void recalculateFrameSizes()
Recalculates the portion of the multiframe item which is shown in each of its component frames.
QColor frameStrokeColor() const
Returns the frame's stroke color.
virtual bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)
Sets multiframe state from a DOM element.
void deleteFrames()
Removes and deletes all child frames.
void setResizeMode(ResizeMode mode)
Sets the resize mode for the multiframe, and recalculates frame sizes to match.
void setItemOpacity(double opacity)
Sets the item's opacity.
virtual void addFrame(QgsLayoutFrame *frame, bool recalcFrameSizes=true)
Adds a frame to the multiframe.
int frameIndex(QgsLayoutFrame *frame) const
Returns the index of a frame within the multiframe.
friend class QgsLayoutFrame
QgsLayoutFrame * createNewFrame(QgsLayoutFrame *currentFrame, QPointF pos, QSizeF size)
Creates a new frame and adds it to the multi frame and layout.
QPointF pagePos() const
Returns the item's position (in layout units) relative to the top left corner of its current page.
virtual QString displayName() const
Returns the multiframe display name.
bool writeObjectPropertiesToElement(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores object properties within an XML DOM element.
@ UseExistingFrames
Don't automatically create new frames, just use existing frames.
DataDefinedProperty
Data defined properties for different item types.
A base class for objects which belong to a layout.