QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgslayoutmultiframe.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutmultiframe.h
3 --------------------
4 begin : October 2017
5 copyright : (C) 2017 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSLAYOUTMULTIFRAME_H
17#define QGSLAYOUTMULTIFRAME_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21#include "qgsapplication.h"
22#include "qgslayoutobject.h"
24
25#include <QIcon>
26#include <QObject>
27#include <QPointF>
28#include <QSizeF>
29
30class QgsLayoutFrame;
31class QgsLayoutItem;
32class QgsLayout;
33class QDomDocument;
34class QDomElement;
35class QRectF;
36class QPainter;
37class QStyleOptionGraphicsItem;
40
47
49{
50 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemhtml.h" );
51 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemattributetable.h" );
52 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemmanualtable.h" );
53 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemtexttable.h" );
54
55#ifdef SIP_RUN
57 // the conversions have to be static, because they're using multiple inheritance
58 // (seen in PyQt4 .sip files for some QGraphicsItem classes)
59 if ( QgsLayoutMultiFrame *mf = qobject_cast< QgsLayoutMultiFrame *>( sipCpp ) )
60 {
61 switch ( mf->type() )
62 {
63 // really, these *should* use the constants from QgsLayoutItemRegistry, but sip doesn't like that!
64 case QGraphicsItem::UserType + 112:
65 sipType = sipType_QgsLayoutItemHtml;
66 *sipCppRet = static_cast<QgsLayoutItemHtml *>( sipCpp );
67 break;
68 case QGraphicsItem::UserType + 113:
69 sipType = sipType_QgsLayoutItemAttributeTable;
70 *sipCppRet = static_cast<QgsLayoutItemAttributeTable *>( sipCpp );
71 break;
72 case QGraphicsItem::UserType + 114:
73 sipType = sipType_QgsLayoutItemTextTable;
74 *sipCppRet = static_cast<QgsLayoutItemTextTable *>( sipCpp );
75 break;
76 case QGraphicsItem::UserType + 116:
77 sipType = sipType_QgsLayoutItemManualTable;
78 *sipCppRet = static_cast<QgsLayoutItemManualTable *>( sipCpp );
79 break;
80 default:
81 sipType = 0;
82 }
83 }
84 else
85 {
86 sipType = 0;
87 }
89#endif
90
91 Q_OBJECT
92
93 public:
94
106
123
128
129 ~QgsLayoutMultiFrame() override;
130
136 QString uuid() const { return mUuid; }
137
141 virtual QSizeF totalSize() const = 0;
142
146 virtual int type() const = 0;
147
151 virtual QIcon icon() const { return QgsApplication::getThemeIcon( QStringLiteral( "/mLayoutItem.svg" ) ); }
152
163 virtual QSizeF fixedFrameSize( int frameIndex = -1 ) const;
164
175 virtual QSizeF minFrameSize( int frameIndex = -1 ) const;
176
183 virtual void render( QgsLayoutItemRenderContext &context, const QRectF &renderExtent, int frameIndex ) = 0;
184
192 virtual void addFrame( QgsLayoutFrame *frame SIP_TRANSFER, bool recalcFrameSizes = true );
193
200 virtual double findNearbyPageBreak( double yPos );
201
212 void removeFrame( int index, bool removeEmptyPages = false );
213
218 void deleteFrames();
219
224 void setResizeMode( ResizeMode mode );
225
231
240 bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context, bool includeFrames = false ) const;
241
250 bool readXml( const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context, bool includeFrames = false );
251
256 QList<QgsLayoutFrame *> frames() const;
257
262 int frameCount() const { return mFrameItems.size(); }
263
268 QgsLayoutFrame *frame( int index ) const;
269
275 int frameIndex( QgsLayoutFrame *frame ) const;
276
284 QgsLayoutFrame *createNewFrame( QgsLayoutFrame *currentFrame, QPointF pos, QSizeF size );
285
289 virtual QString displayName() const;
290
291 QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id, QUndoCommand *parent = nullptr ) override SIP_FACTORY;
292
293 QgsExpressionContext createExpressionContext() const override;
294
303 void beginCommand( const QString &commandText, UndoCommand command = UndoNone );
304
310 void endCommand();
311
317 void cancelCommand();
318
327 virtual void finalizeRestoreFromXml();
328
329 public slots:
330
334 void refresh() override;
335
339 void update();
340
348 virtual void recalculateFrameSizes();
349
358 void recalculateFrameRects();
359
366 virtual void refreshDataDefinedProperty( QgsLayoutObject::DataDefinedProperty property = QgsLayoutObject::DataDefinedProperty::AllProperties );
367
368 signals:
369
375
376 protected:
377
386 virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
387
403 virtual bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context );
404
406
408
409 private slots:
410
414 void handlePageChange();
415
420 void handleFrameRemoval( QgsLayoutFrame *frame );
421
422
423 private:
424 QgsLayoutMultiFrame() = delete;
425
426 bool mIsRecalculatingSize = false;
427
428 bool mBlockUpdates = false;
429 bool mBlockUndoCommands = false;
430
431 QList< QString > mFrameUuids;
432 QList< QString > mFrameTemplateUuids;
433
435 QString mUuid;
436 QString mTemplateUuid;
437 friend class QgsLayoutFrame;
438 friend class QgsLayout;
439};
440
441
442#endif // QGSLAYOUTMULTIFRAME_H
Base class for commands to undo/redo layout and layout object changes.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Base class for frame items, which form a layout multiframe item.
A layout table subclass that displays attributes from a vector layer.
A layout multiframe subclass for HTML content.
A layout table subclass that displays manually entered (and formatted) content.
Contains settings and helpers relating to a render of a QgsLayoutItem.
A text table item that reads text from string lists.
Base class for graphical items within a QgsLayout.
Abstract base class for layout items with the ability to distribute the content to several frames (Qg...
virtual bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores multiframe state within an XML DOM element.
void setResizeMode(ResizeMode mode)
Sets the resize mode for the multiframe, and recalculates frame sizes to match.
virtual QSizeF totalSize() const =0
Returns the total size of the multiframe's content, in layout units.
int frameCount() const
Returns the number of frames associated with this multiframe.
virtual void addFrame(QgsLayoutFrame *frame, bool recalcFrameSizes=true)
Adds a frame to the multiframe.
QgsLayoutMultiFrame(QgsLayout *layout)
Construct a new multiframe item, attached to the specified layout.
void contentsChanged()
Emitted when the contents of the multi frame have changed and the frames must be redrawn.
void deleteFrames()
Removes and deletes all child frames.
QgsLayoutFrame * frame(int index) const
Returns the child frame at a specified index from the multiframe.
void removeFrame(int index, bool removeEmptyPages=false)
Removes a frame by index from the multiframe.
QList< QgsLayoutFrame * > mFrameItems
virtual int type() const =0
Returns unique multiframe type id.
virtual QIcon icon() const
Returns the item's icon.
ResizeMode resizeMode() const
Returns the resize mode for the multiframe.
virtual double findNearbyPageBreak(double yPos)
Finds the optimal position to break a frame at.
QString uuid() const
Returns the multiframe identification string.
ResizeMode
Specifies the behavior for creating new frames to fit the multiframe's content.
@ UseExistingFrames
Don't automatically create new frames, just use existing frames.
@ RepeatOnEveryPage
Repeats the same frame on every page.
@ ExtendToNextPage
Creates new full page frames on the following page(s) until the entire multiframe content is visible.
int frameIndex(QgsLayoutFrame *frame) const
Returns the index of a frame within the multiframe.
virtual bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)
Sets multiframe state from a DOM element.
UndoCommand
Multiframe item undo commands, used for collapsing undo commands.
@ UndoTableMaximumFeatures
Maximum features in table.
@ UndoTableBackgroundColor
Table background color.
@ UndoTableContentFontColor
Table content font color.
@ UndoHtmlBreakDistance
HTML page break distance.
@ UndoTableCellStyle
Table cell style.
@ UndoHtmlStylesheet
HTML stylesheet.
@ UndoTableGridStrokeWidth
Table grid stroke width.
@ UndoTableGridColor
Table grid color.
@ UndoTableHeaderFontColor
Table header font color.
@ UndoNone
No command suppression.
@ UndoTableMargin
Table margins.
virtual void render(QgsLayoutItemRenderContext &context, const QRectF &renderExtent, int frameIndex)=0
Renders a portion of the multiframe's content into a render context.
A base class for objects which belong to a layout.
QgsLayoutObject(QgsLayout *layout)
Constructor for QgsLayoutObject, with the specified parent layout.
Interface for layout objects which support undo/redo commands.
virtual QgsAbstractLayoutUndoCommand * createCommand(const QString &text, int id=0, QUndoCommand *parent=nullptr)=0
Creates a new layout undo command with the specified text and parent.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:50
A container for the context for various read/write operations on objects.
Contains information about the context of a rendering operation.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:199
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:84
#define SIP_END
Definition qgis_sip.h:216