QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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.h"
21 #include "qgslayoutobject.h"
22 #include "qgslayoutundocommand.h"
23 #include <QIcon>
24 #include <QObject>
25 #include <QSizeF>
26 #include <QPointF>
27 
28 class QgsLayoutFrame;
29 class QgsLayoutItem;
30 class QgsLayout;
31 class QDomDocument;
32 class QDomElement;
33 class QRectF;
34 class QPainter;
35 class QStyleOptionGraphicsItem;
36 class QgsRenderContext;
38 
48 {
49 #ifdef SIP_RUN
50 #include "qgslayoutitemhtml.h"
52 #include "qgslayoutitemtexttable.h"
53 #endif
54 
55 
56 #ifdef SIP_RUN
58  // the conversions have to be static, because they're using multiple inheritance
59  // (seen in PyQt4 .sip files for some QGraphicsItem classes)
60  if ( QgsLayoutMultiFrame *mf = qobject_cast< QgsLayoutMultiFrame *>( sipCpp ) )
61  {
62  switch ( mf->type() )
63  {
64  // really, these *should* use the constants from QgsLayoutItemRegistry, but sip doesn't like that!
65  case QGraphicsItem::UserType + 112:
66  sipType = sipType_QgsLayoutItemHtml;
67  *sipCppRet = static_cast<QgsLayoutItemHtml *>( sipCpp );
68  break;
69  case QGraphicsItem::UserType + 113:
70  sipType = sipType_QgsLayoutItemAttributeTable;
71  *sipCppRet = static_cast<QgsLayoutItemAttributeTable *>( sipCpp );
72  break;
73  case QGraphicsItem::UserType + 114:
74  sipType = sipType_QgsLayoutItemTextTable;
75  *sipCppRet = static_cast<QgsLayoutItemTextTable *>( sipCpp );
76  break;
77  default:
78  sipType = 0;
79  }
80  }
81  else
82  {
83  sipType = 0;
84  }
85  SIP_END
86 #endif
87 
88  Q_OBJECT
89 
90  public:
91 
96  {
97  UseExistingFrames = 0,
100  RepeatUntilFinished
102  };
103 
106  {
118  UndoNone = -1,
119  };
120 
125 
126  ~QgsLayoutMultiFrame() override;
127 
133  QString uuid() const { return mUuid; }
134 
138  virtual QSizeF totalSize() const = 0;
139 
143  virtual int type() const = 0;
144 
148  virtual QIcon icon() const { return QgsApplication::getThemeIcon( QStringLiteral( "/mLayoutItem.svg" ) ); }
149 
160  virtual QSizeF fixedFrameSize( int frameIndex = -1 ) const;
161 
172  virtual QSizeF minFrameSize( int frameIndex = -1 ) const;
173 
180  virtual void render( QgsLayoutItemRenderContext &context, const QRectF &renderExtent, int frameIndex ) = 0;
181 
189  virtual void addFrame( QgsLayoutFrame *frame SIP_TRANSFER, bool recalcFrameSizes = true );
190 
197  virtual double findNearbyPageBreak( double yPos );
198 
209  void removeFrame( int index, bool removeEmptyPages = false );
210 
215  void deleteFrames();
216 
221  void setResizeMode( ResizeMode mode );
222 
227  ResizeMode resizeMode() const { return mResizeMode; }
228 
237  bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context, bool includeFrames = false ) const;
238 
247  bool readXml( const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context, bool includeFrames = false );
248 
253  QList<QgsLayoutFrame *> frames() const;
254 
259  int frameCount() const { return mFrameItems.size(); }
260 
265  QgsLayoutFrame *frame( int index ) const;
266 
272  int frameIndex( QgsLayoutFrame *frame ) const;
273 
281  QgsLayoutFrame *createNewFrame( QgsLayoutFrame *currentFrame, QPointF pos, QSizeF size );
282 
286  virtual QString displayName() const;
287 
288  QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id, QUndoCommand *parent = nullptr ) override SIP_FACTORY;
289 
298  void beginCommand( const QString &commandText, UndoCommand command = UndoNone );
299 
305  void endCommand();
306 
312  void cancelCommand();
313 
322  virtual void finalizeRestoreFromXml();
323 
324  public slots:
325 
329  void refresh() override;
330 
334  void update();
335 
343  virtual void recalculateFrameSizes();
344 
353  void recalculateFrameRects();
354 
361  virtual void refreshDataDefinedProperty( QgsLayoutObject::DataDefinedProperty property = QgsLayoutObject::AllProperties );
362 
363  signals:
364 
369  void contentsChanged();
370 
371  protected:
372 
381  virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
382 
398  virtual bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context );
399 
400  QList<QgsLayoutFrame *> mFrameItems;
401 
402  ResizeMode mResizeMode = UseExistingFrames;
403 
404  private slots:
405 
409  void handlePageChange();
410 
415  void handleFrameRemoval( QgsLayoutFrame *frame );
416 
417 
418  private:
419  QgsLayoutMultiFrame() = delete;
420 
421  bool mIsRecalculatingSize = false;
422 
423  bool mBlockUpdates = false;
424  bool mBlockUndoCommands = false;
425 
426  QList< QString > mFrameUuids;
427  QList< QString > mFrameTemplateUuids;
428 
430  QString mUuid;
431  QString mTemplateUuid;
432  friend class QgsLayoutFrame;
433  friend class QgsLayout;
434 };
435 
436 
437 #endif // QGSLAYOUTMULTIFRAME_H
The class is used as a container of context for various read/write operations on other objects...
Base class for graphical items within a QgsLayout.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
Base class for commands to undo/redo layout and layout object changes.
ResizeMode resizeMode() const
Returns the resize mode for the multiframe.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
QList< QgsLayoutFrame * > mFrameItems
Creates new full page frames on the following page(s) until the entire multiframe content is visible...
Abstract base class for layout items with the ability to distribute the content to several frames (Qg...
int frameCount() const
Returns the number of frames associated with this multiframe.
virtual QIcon icon() const
Returns the item&#39;s icon.
Repeats the same frame on every page.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_END
Definition: qgis_sip.h:182
A layout table subclass that displays attributes from a vector layer.
#define SIP_FACTORY
Definition: qgis_sip.h:69
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
Contains settings and helpers relating to a render of a QgsLayoutItem.
Definition: qgslayoutitem.h:43
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.
ResizeMode
Specifies the behavior for creating new frames to fit the multiframe&#39;s content.
Contains information about the context of a rendering operation.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:165
Interface for layout objects which support undo/redo commands.
QString uuid() const
Returns the multiframe identification string.
A base class for objects which belong to a layout.
UndoCommand
Multiframe item undo commands, used for collapsing undo commands.
virtual void refresh()
Refreshes the object, causing a recalculation of any property overrides.
DataDefinedProperty
Data defined properties for different item types.
Base class for frame items, which form a layout multiframe item.
A layout multiframe subclass for HTML content.
A text table item that reads text from string lists.
All properties for item.