QGIS API Documentation  3.20.0-Odense (decaadbb31)
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
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.
Definition: qgslayoutitem.h:45
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.
@ UndoHtmlSource
HTML source.
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:51
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:177
#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:194