QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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"
22 #include "qgslayoutundocommand.h"
23 #include "qgsapplication.h"
24 #include <QIcon>
25 #include <QObject>
26 #include <QSizeF>
27 #include <QPointF>
28 
29 class QgsLayoutFrame;
30 class QgsLayoutItem;
31 class QgsLayout;
32 class QDomDocument;
33 class QDomElement;
34 class QRectF;
35 class QPainter;
36 class QStyleOptionGraphicsItem;
37 class QgsRenderContext;
39 
49 {
50 #ifdef SIP_RUN
51 #include "qgslayoutitemhtml.h"
54 #include "qgslayoutitemtexttable.h"
55 #endif
56 
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  }
91  SIP_END
92 #endif
93 
94  Q_OBJECT
95 
96  public:
97 
102  {
103  UseExistingFrames = 0,
106  RepeatUntilFinished
108  };
109 
112  {
124  UndoNone = -1,
125  };
126 
131 
132  ~QgsLayoutMultiFrame() override;
133 
139  QString uuid() const { return mUuid; }
140 
144  virtual QSizeF totalSize() const = 0;
145 
149  virtual int type() const = 0;
150 
154  virtual QIcon icon() const { return QgsApplication::getThemeIcon( QStringLiteral( "/mLayoutItem.svg" ) ); }
155 
166  virtual QSizeF fixedFrameSize( int frameIndex = -1 ) const;
167 
178  virtual QSizeF minFrameSize( int frameIndex = -1 ) const;
179 
186  virtual void render( QgsLayoutItemRenderContext &context, const QRectF &renderExtent, int frameIndex ) = 0;
187 
195  virtual void addFrame( QgsLayoutFrame *frame SIP_TRANSFER, bool recalcFrameSizes = true );
196 
203  virtual double findNearbyPageBreak( double yPos );
204 
215  void removeFrame( int index, bool removeEmptyPages = false );
216 
221  void deleteFrames();
222 
227  void setResizeMode( ResizeMode mode );
228 
233  ResizeMode resizeMode() const { return mResizeMode; }
234 
243  bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context, bool includeFrames = false ) const;
244 
253  bool readXml( const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context, bool includeFrames = false );
254 
259  QList<QgsLayoutFrame *> frames() const;
260 
265  int frameCount() const { return mFrameItems.size(); }
266 
271  QgsLayoutFrame *frame( int index ) const;
272 
278  int frameIndex( QgsLayoutFrame *frame ) const;
279 
287  QgsLayoutFrame *createNewFrame( QgsLayoutFrame *currentFrame, QPointF pos, QSizeF size );
288 
292  virtual QString displayName() const;
293 
294  QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id, QUndoCommand *parent = nullptr ) override SIP_FACTORY;
295 
296  QgsExpressionContext createExpressionContext() const override;
297 
306  void beginCommand( const QString &commandText, UndoCommand command = UndoNone );
307 
313  void endCommand();
314 
320  void cancelCommand();
321 
330  virtual void finalizeRestoreFromXml();
331 
332  public slots:
333 
337  void refresh() override;
338 
342  void update();
343 
351  virtual void recalculateFrameSizes();
352 
361  void recalculateFrameRects();
362 
369  virtual void refreshDataDefinedProperty( QgsLayoutObject::DataDefinedProperty property = QgsLayoutObject::AllProperties );
370 
371  signals:
372 
377  void contentsChanged();
378 
379  protected:
380 
389  virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
390 
406  virtual bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context );
407 
408  QList<QgsLayoutFrame *> mFrameItems;
409 
410  ResizeMode mResizeMode = UseExistingFrames;
411 
412  private slots:
413 
417  void handlePageChange();
418 
423  void handleFrameRemoval( QgsLayoutFrame *frame );
424 
425 
426  private:
427  QgsLayoutMultiFrame() = delete;
428 
429  bool mIsRecalculatingSize = false;
430 
431  bool mBlockUpdates = false;
432  bool mBlockUndoCommands = false;
433 
434  QList< QString > mFrameUuids;
435  QList< QString > mFrameTemplateUuids;
436 
438  QString mUuid;
439  QString mTemplateUuid;
440  friend class QgsLayoutFrame;
441  friend class QgsLayout;
442 };
443 
444 
445 #endif // QGSLAYOUTMULTIFRAME_H
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:370
QgsLayoutUndoObjectInterface::createCommand
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.
QgsLayoutMultiFrame::totalSize
virtual QSizeF totalSize() const =0
Returns the total size of the multiframe's content, in layout units.
qgslayoutitemattributetable.h
QgsLayoutMultiFrame::UndoHtmlBreakDistance
@ UndoHtmlBreakDistance
HTML page break distance.
Definition: qgslayoutmultiframe.h:113
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
Definition: qgsapplication.cpp:626
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
QgsLayoutMultiFrame::UndoTableCellStyle
@ UndoTableCellStyle
Table cell style.
Definition: qgslayoutmultiframe.h:116
QgsLayoutItemRenderContext
Contains settings and helpers relating to a render of a QgsLayoutItem.
Definition: qgslayoutitem.h:45
QgsLayoutItemHtml
A layout multiframe subclass for HTML content.
Definition: qgslayoutitemhtml.h:37
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:58
QgsLayoutMultiFrame
Abstract base class for layout items with the ability to distribute the content to several frames (Qg...
Definition: qgslayoutmultiframe.h:49
QgsLayoutMultiFrame::icon
virtual QIcon icon() const
Returns the item's icon.
Definition: qgslayoutmultiframe.h:154
QgsLayoutMultiFrame::UndoTableHeaderFontColor
@ UndoTableHeaderFontColor
Table header font color.
Definition: qgslayoutmultiframe.h:119
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsLayoutMultiFrame::ExtendToNextPage
@ ExtendToNextPage
Creates new full page frames on the following page(s) until the entire multiframe content is visible.
Definition: qgslayoutmultiframe.h:104
qgsapplication.h
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:177
QgsLayoutMultiFrame::UndoHtmlStylesheet
@ UndoHtmlStylesheet
HTML stylesheet.
Definition: qgslayoutmultiframe.h:115
QgsLayoutMultiFrame::type
virtual int type() const =0
Returns unique multiframe type id.
QgsLayoutMultiFrame::UndoTableGridColor
@ UndoTableGridColor
Table grid color.
Definition: qgslayoutmultiframe.h:122
QgsLayoutFrame
Base class for frame items, which form a layout multiframe item.
Definition: qgslayoutframe.h:32
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsLayoutMultiFrame::ResizeMode
ResizeMode
Specifies the behavior for creating new frames to fit the multiframe's content.
Definition: qgslayoutmultiframe.h:102
QgsLayoutMultiFrame::UndoTableContentFontColor
@ UndoTableContentFontColor
Table content font color.
Definition: qgslayoutmultiframe.h:120
QgsLayoutMultiFrame::UndoTableBackgroundColor
@ UndoTableBackgroundColor
Table background color.
Definition: qgslayoutmultiframe.h:123
QgsLayoutItemAttributeTable
A layout table subclass that displays attributes from a vector layer.
Definition: qgslayoutitemattributetable.h:35
QgsLayoutMultiFrame::resizeMode
ResizeMode resizeMode() const
Returns the resize mode for the multiframe.
Definition: qgslayoutmultiframe.h:233
QgsLayoutItem
Base class for graphical items within a QgsLayout.
Definition: qgslayoutitem.h:113
qgslayoutundocommand.h
QgsLayoutMultiFrame::UndoTableMaximumFeatures
@ UndoTableMaximumFeatures
Maximum features in table.
Definition: qgslayoutmultiframe.h:117
QgsLayoutMultiFrame::render
virtual void render(QgsLayoutItemRenderContext &context, const QRectF &renderExtent, int frameIndex)=0
Renders a portion of the multiframe's content into a render context.
QgsLayoutUndoObjectInterface
Interface for layout objects which support undo/redo commands.
Definition: qgslayoutundocommand.h:129
qgslayoutitemmanualtable.h
QgsLayoutMultiFrame::uuid
QString uuid() const
Returns the multiframe identification string.
Definition: qgslayoutmultiframe.h:139
QgsLayoutItemTextTable
A text table item that reads text from string lists.
Definition: qgslayoutitemtexttable.h:31
QgsAbstractLayoutUndoCommand
Base class for commands to undo/redo layout and layout object changes.
Definition: qgslayoutundocommand.h:35
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:50
QgsLayoutMultiFrame::RepeatOnEveryPage
@ RepeatOnEveryPage
Repeats the same frame on every page.
Definition: qgslayoutmultiframe.h:105
QgsLayoutMultiFrame::UndoCommand
UndoCommand
Multiframe item undo commands, used for collapsing undo commands.
Definition: qgslayoutmultiframe.h:112
qgslayoutitemtexttable.h
qgslayoutobject.h
SIP_END
#define SIP_END
Definition: qgis_sip.h:194
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsLayoutMultiFrame::UndoTableGridStrokeWidth
@ UndoTableGridStrokeWidth
Table grid stroke width.
Definition: qgslayoutmultiframe.h:121
QgsLayoutMultiFrame::UndoTableMargin
@ UndoTableMargin
Table margins.
Definition: qgslayoutmultiframe.h:118
QgsLayoutItemManualTable
A layout table subclass that displays manually entered (and formatted) content.
Definition: qgslayoutitemmanualtable.h:32
QgsLayoutMultiFrame::frameCount
int frameCount() const
Returns the number of frames associated with this multiframe.
Definition: qgslayoutmultiframe.h:265
qgslayoutitemhtml.h
QgsLayoutObject
A base class for objects which belong to a layout.
Definition: qgslayoutobject.h:40
QgsLayoutMultiFrame::UndoHtmlSource
@ UndoHtmlSource
HTML source.
Definition: qgslayoutmultiframe.h:114