QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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#ifdef SIP_RUN
50#include "qgslayoutitemhtml.h"
54#endif
55
56
57#ifdef SIP_RUN
59 // the conversions have to be static, because they're using multiple inheritance
60 // (seen in PyQt4 .sip files for some QGraphicsItem classes)
61 if ( QgsLayoutMultiFrame *mf = qobject_cast< QgsLayoutMultiFrame *>( sipCpp ) )
62 {
63 switch ( mf->type() )
64 {
65 // really, these *should* use the constants from QgsLayoutItemRegistry, but sip doesn't like that!
66 case QGraphicsItem::UserType + 112:
67 sipType = sipType_QgsLayoutItemHtml;
68 *sipCppRet = static_cast<QgsLayoutItemHtml *>( sipCpp );
69 break;
70 case QGraphicsItem::UserType + 113:
71 sipType = sipType_QgsLayoutItemAttributeTable;
72 *sipCppRet = static_cast<QgsLayoutItemAttributeTable *>( sipCpp );
73 break;
74 case QGraphicsItem::UserType + 114:
75 sipType = sipType_QgsLayoutItemTextTable;
76 *sipCppRet = static_cast<QgsLayoutItemTextTable *>( sipCpp );
77 break;
78 case QGraphicsItem::UserType + 116:
79 sipType = sipType_QgsLayoutItemManualTable;
80 *sipCppRet = static_cast<QgsLayoutItemManualTable *>( sipCpp );
81 break;
82 default:
83 sipType = 0;
84 }
85 }
86 else
87 {
88 sipType = 0;
89 }
91#endif
92
93 Q_OBJECT
94
95 public:
96
101 {
102 UseExistingFrames = 0,
105 RepeatUntilFinished
107 };
108
125
130
131 ~QgsLayoutMultiFrame() override;
132
138 QString uuid() const { return mUuid; }
139
143 virtual QSizeF totalSize() const = 0;
144
148 virtual int type() const = 0;
149
153 virtual QIcon icon() const { return QgsApplication::getThemeIcon( QStringLiteral( "/mLayoutItem.svg" ) ); }
154
165 virtual QSizeF fixedFrameSize( int frameIndex = -1 ) const;
166
177 virtual QSizeF minFrameSize( int frameIndex = -1 ) const;
178
185 virtual void render( QgsLayoutItemRenderContext &context, const QRectF &renderExtent, int frameIndex ) = 0;
186
194 virtual void addFrame( QgsLayoutFrame *frame SIP_TRANSFER, bool recalcFrameSizes = true );
195
202 virtual double findNearbyPageBreak( double yPos );
203
214 void removeFrame( int index, bool removeEmptyPages = false );
215
220 void deleteFrames();
221
226 void setResizeMode( ResizeMode mode );
227
232 ResizeMode resizeMode() const { return mResizeMode; }
233
242 bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context, bool includeFrames = false ) const;
243
252 bool readXml( const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context, bool includeFrames = false );
253
258 QList<QgsLayoutFrame *> frames() const;
259
264 int frameCount() const { return mFrameItems.size(); }
265
270 QgsLayoutFrame *frame( int index ) const;
271
277 int frameIndex( QgsLayoutFrame *frame ) const;
278
286 QgsLayoutFrame *createNewFrame( QgsLayoutFrame *currentFrame, QPointF pos, QSizeF size );
287
291 virtual QString displayName() const;
292
293 QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id, QUndoCommand *parent = nullptr ) override SIP_FACTORY;
294
295 QgsExpressionContext createExpressionContext() const override;
296
305 void beginCommand( const QString &commandText, UndoCommand command = UndoNone );
306
312 void endCommand();
313
319 void cancelCommand();
320
329 virtual void finalizeRestoreFromXml();
330
331 public slots:
332
336 void refresh() override;
337
341 void update();
342
350 virtual void recalculateFrameSizes();
351
360 void recalculateFrameRects();
361
368 virtual void refreshDataDefinedProperty( QgsLayoutObject::DataDefinedProperty property = QgsLayoutObject::DataDefinedProperty::AllProperties );
369
370 signals:
371
376 void contentsChanged();
377
378 protected:
379
388 virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
389
405 virtual bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context );
406
407 QList<QgsLayoutFrame *> mFrameItems;
408
409 ResizeMode mResizeMode = UseExistingFrames;
410
411 private slots:
412
416 void handlePageChange();
417
422 void handleFrameRemoval( QgsLayoutFrame *frame );
423
424
425 private:
426 QgsLayoutMultiFrame() = delete;
427
428 bool mIsRecalculatingSize = false;
429
430 bool mBlockUpdates = false;
431 bool mBlockUndoCommands = false;
432
433 QList< QString > mFrameUuids;
434 QList< QString > mFrameTemplateUuids;
435
437 QString mUuid;
438 QString mTemplateUuid;
439 friend class QgsLayoutFrame;
440 friend class QgsLayout;
441};
442
443
444#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