QGIS API Documentation 4.1.0-Master (60fea48833c)
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#include <QString>
30
31using namespace Qt::StringLiterals;
32
33class QgsLayoutFrame;
34class QgsLayoutItem;
35class QgsLayout;
36class QDomDocument;
37class QDomElement;
38class QRectF;
39class QPainter;
40class QStyleOptionGraphicsItem;
43
50
52{
53 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemhtml.h" );
54 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemattributetable.h" );
55 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemmanualtable.h" );
56 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemtexttable.h" );
57
58#ifdef SIP_RUN
60 // the conversions have to be static, because they're using multiple inheritance
61 // (seen in PyQt4 .sip files for some QGraphicsItem classes)
62 if ( QgsLayoutMultiFrame *mf = qobject_cast< QgsLayoutMultiFrame *>( sipCpp ) )
63 {
64 switch ( mf->type() )
65 {
66 // really, these *should* use the constants from QgsLayoutItemRegistry, but sip doesn't like that!
67 case QGraphicsItem::UserType + 112:
68 sipType = sipType_QgsLayoutItemHtml;
69 *sipCppRet = static_cast<QgsLayoutItemHtml *>( sipCpp );
70 break;
71 case QGraphicsItem::UserType + 113:
72 sipType = sipType_QgsLayoutItemAttributeTable;
73 *sipCppRet = static_cast<QgsLayoutItemAttributeTable *>( sipCpp );
74 break;
75 case QGraphicsItem::UserType + 114:
76 sipType = sipType_QgsLayoutItemTextTable;
77 *sipCppRet = static_cast<QgsLayoutItemTextTable *>( sipCpp );
78 break;
79 case QGraphicsItem::UserType + 116:
80 sipType = sipType_QgsLayoutItemManualTable;
81 *sipCppRet = static_cast<QgsLayoutItemManualTable *>( sipCpp );
82 break;
83 default:
84 sipType = 0;
85 }
86 }
87 else
88 {
89 sipType = 0;
90 }
92#endif
93
94 // clang-format off
95 Q_OBJECT
96
97 public:
98
110
128
133
134 ~QgsLayoutMultiFrame() override;
135
141 QString uuid() const { return mUuid; }
142
146 virtual QSizeF totalSize() const = 0;
147
151 virtual int type() const = 0;
152
156 virtual QIcon icon() const { return QgsApplication::getThemeIcon( u"/mLayoutItem.svg"_s ); }
157
168 virtual QSizeF fixedFrameSize( int frameIndex = -1 ) const;
169
180 virtual QSizeF minFrameSize( int frameIndex = -1 ) const;
181
188 virtual void render( QgsLayoutItemRenderContext &context, const QRectF &renderExtent, int frameIndex ) = 0;
189
197 virtual void addFrame( QgsLayoutFrame *frame SIP_TRANSFER, bool recalcFrameSizes = true );
198
205 virtual double findNearbyPageBreak( double yPos );
206
217 void removeFrame( int index, bool removeEmptyPages = false );
218
223 void deleteFrames();
224
229 void setResizeMode( ResizeMode mode );
230
236
245 bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context, bool includeFrames = false ) const;
246
255 bool readXml( const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context, bool includeFrames = false );
256
261 QList<QgsLayoutFrame *> frames() const;
262
267 int frameCount() const { return mFrameItems.size(); }
268
273 QgsLayoutFrame *frame( int index ) const;
274
280 int frameIndex( QgsLayoutFrame *frame ) const;
281
289 QgsLayoutFrame *createNewFrame( QgsLayoutFrame *currentFrame, QPointF pos, QSizeF size );
290
294 virtual QString displayName() const;
295
296 QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id, QUndoCommand *parent = nullptr ) override SIP_FACTORY;
297
298 QgsExpressionContext createExpressionContext() const override;
299
308 void beginCommand( const QString &commandText, UndoCommand command = UndoNone );
309
315 void endCommand();
316
322 void cancelCommand();
323
332 virtual void finalizeRestoreFromXml();
333
334 public slots:
335
339 void refresh() override;
340
344 void update();
345
353 virtual void recalculateFrameSizes();
354
363 void recalculateFrameRects();
364
371 virtual void refreshDataDefinedProperty( QgsLayoutObject::DataDefinedProperty property = QgsLayoutObject::DataDefinedProperty::AllProperties );
372
373 signals:
374
380
381 protected:
390 virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
391
407 virtual bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context );
408
410
412
413 private slots:
414
418 void handlePageChange();
419
424 void handleFrameRemoval( QgsLayoutFrame *frame );
425
426
427 private:
428 QgsLayoutMultiFrame() = delete;
429
430 bool mIsRecalculatingSize = false;
431
432 bool mBlockUpdates = false;
433 bool mBlockUndoCommands = false;
434
435 QList< QString > mFrameUuids;
436 QList< QString > mFrameTemplateUuids;
437
439 QString mUuid;
440 QString mTemplateUuid;
441 friend class QgsLayoutFrame;
442 friend class QgsLayout;
443};
444
445
446#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:198
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_END
Definition qgis_sip.h:215