QGIS API Documentation 3.41.0-Master (af5edcb665c)
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 "qgslayoutobject.h"
23#include "qgsapplication.h"
24#include <QIcon>
25#include <QObject>
26#include <QSizeF>
27#include <QPointF>
28
29class QgsLayoutFrame;
30class QgsLayoutItem;
31class QgsLayout;
32class QDomDocument;
33class QDomElement;
34class QRectF;
35class QPainter;
36class QStyleOptionGraphicsItem;
39
48{
49 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemhtml.h" );
50 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemattributetable.h" );
51 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemmanualtable.h" );
52 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemtexttable.h" );
53
54#ifdef SIP_RUN
56 // the conversions have to be static, because they're using multiple inheritance
57 // (seen in PyQt4 .sip files for some QGraphicsItem classes)
58 if ( QgsLayoutMultiFrame *mf = qobject_cast< QgsLayoutMultiFrame *>( sipCpp ) )
59 {
60 switch ( mf->type() )
61 {
62 // really, these *should* use the constants from QgsLayoutItemRegistry, but sip doesn't like that!
63 case QGraphicsItem::UserType + 112:
64 sipType = sipType_QgsLayoutItemHtml;
65 *sipCppRet = static_cast<QgsLayoutItemHtml *>( sipCpp );
66 break;
67 case QGraphicsItem::UserType + 113:
68 sipType = sipType_QgsLayoutItemAttributeTable;
69 *sipCppRet = static_cast<QgsLayoutItemAttributeTable *>( sipCpp );
70 break;
71 case QGraphicsItem::UserType + 114:
72 sipType = sipType_QgsLayoutItemTextTable;
73 *sipCppRet = static_cast<QgsLayoutItemTextTable *>( sipCpp );
74 break;
75 case QGraphicsItem::UserType + 116:
76 sipType = sipType_QgsLayoutItemManualTable;
77 *sipCppRet = static_cast<QgsLayoutItemManualTable *>( sipCpp );
78 break;
79 default:
80 sipType = 0;
81 }
82 }
83 else
84 {
85 sipType = 0;
86 }
88#endif
89
90 Q_OBJECT
91
92 public:
93
98 {
99 UseExistingFrames = 0,
102 RepeatUntilFinished
104 };
105
122
127
128 ~QgsLayoutMultiFrame() override;
129
135 QString uuid() const { return mUuid; }
136
140 virtual QSizeF totalSize() const = 0;
141
145 virtual int type() const = 0;
146
150 virtual QIcon icon() const { return QgsApplication::getThemeIcon( QStringLiteral( "/mLayoutItem.svg" ) ); }
151
162 virtual QSizeF fixedFrameSize( int frameIndex = -1 ) const;
163
174 virtual QSizeF minFrameSize( int frameIndex = -1 ) const;
175
182 virtual void render( QgsLayoutItemRenderContext &context, const QRectF &renderExtent, int frameIndex ) = 0;
183
191 virtual void addFrame( QgsLayoutFrame *frame SIP_TRANSFER, bool recalcFrameSizes = true );
192
199 virtual double findNearbyPageBreak( double yPos );
200
211 void removeFrame( int index, bool removeEmptyPages = false );
212
217 void deleteFrames();
218
223 void setResizeMode( ResizeMode mode );
224
229 ResizeMode resizeMode() const { return mResizeMode; }
230
239 bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context, bool includeFrames = false ) const;
240
249 bool readXml( const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context, bool includeFrames = false );
250
255 QList<QgsLayoutFrame *> frames() const;
256
261 int frameCount() const { return mFrameItems.size(); }
262
267 QgsLayoutFrame *frame( int index ) const;
268
274 int frameIndex( QgsLayoutFrame *frame ) const;
275
283 QgsLayoutFrame *createNewFrame( QgsLayoutFrame *currentFrame, QPointF pos, QSizeF size );
284
288 virtual QString displayName() const;
289
290 QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id, QUndoCommand *parent = nullptr ) override SIP_FACTORY;
291
292 QgsExpressionContext createExpressionContext() const override;
293
302 void beginCommand( const QString &commandText, UndoCommand command = UndoNone );
303
309 void endCommand();
310
316 void cancelCommand();
317
326 virtual void finalizeRestoreFromXml();
327
328 public slots:
329
333 void refresh() override;
334
338 void update();
339
347 virtual void recalculateFrameSizes();
348
357 void recalculateFrameRects();
358
365 virtual void refreshDataDefinedProperty( QgsLayoutObject::DataDefinedProperty property = QgsLayoutObject::DataDefinedProperty::AllProperties );
366
367 signals:
368
373 void contentsChanged();
374
375 protected:
376
385 virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
386
402 virtual bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context );
403
404 QList<QgsLayoutFrame *> mFrameItems;
405
406 ResizeMode mResizeMode = UseExistingFrames;
407
408 private slots:
409
413 void handlePageChange();
414
419 void handleFrameRemoval( QgsLayoutFrame *frame );
420
421
422 private:
423 QgsLayoutMultiFrame() = delete;
424
425 bool mIsRecalculatingSize = false;
426
427 bool mBlockUpdates = false;
428 bool mBlockUndoCommands = false;
429
430 QList< QString > mFrameUuids;
431 QList< QString > mFrameTemplateUuids;
432
434 QString mUuid;
435 QString mTemplateUuid;
436 friend class QgsLayoutFrame;
437 friend class QgsLayout;
438};
439
440
441#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 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 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.
QString uuid() const
Returns the multiframe identification string.
ResizeMode
Specifies the behavior for creating new frames to fit the multiframe's content.
@ 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.
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.
@ 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.
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:49
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_END
Definition qgis_sip.h:208