QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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"
53 #include "qgslayoutitemtexttable.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  default:
79  sipType = 0;
80  }
81  }
82  else
83  {
84  sipType = 0;
85  }
86  SIP_END
87 #endif
88 
89  Q_OBJECT
90 
91  public:
92 
97  {
98  UseExistingFrames = 0,
101  RepeatUntilFinished
103  };
104 
107  {
119  UndoNone = -1,
120  };
121 
126 
127  ~QgsLayoutMultiFrame() override;
128 
134  QString uuid() const { return mUuid; }
135 
139  virtual QSizeF totalSize() const = 0;
140 
144  virtual int type() const = 0;
145 
149  virtual QIcon icon() const { return QgsApplication::getThemeIcon( QStringLiteral( "/mLayoutItem.svg" ) ); }
150 
161  virtual QSizeF fixedFrameSize( int frameIndex = -1 ) const;
162 
173  virtual QSizeF minFrameSize( int frameIndex = -1 ) const;
174 
181  virtual void render( QgsLayoutItemRenderContext &context, const QRectF &renderExtent, int frameIndex ) = 0;
182 
190  virtual void addFrame( QgsLayoutFrame *frame SIP_TRANSFER, bool recalcFrameSizes = true );
191 
198  virtual double findNearbyPageBreak( double yPos );
199 
210  void removeFrame( int index, bool removeEmptyPages = false );
211 
216  void deleteFrames();
217 
222  void setResizeMode( ResizeMode mode );
223 
228  ResizeMode resizeMode() const { return mResizeMode; }
229 
238  bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context, bool includeFrames = false ) const;
239 
248  bool readXml( const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context, bool includeFrames = false );
249 
254  QList<QgsLayoutFrame *> frames() const;
255 
260  int frameCount() const { return mFrameItems.size(); }
261 
266  QgsLayoutFrame *frame( int index ) const;
267 
273  int frameIndex( QgsLayoutFrame *frame ) const;
274 
282  QgsLayoutFrame *createNewFrame( QgsLayoutFrame *currentFrame, QPointF pos, QSizeF size );
283 
287  virtual QString displayName() const;
288 
289  QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id, QUndoCommand *parent = nullptr ) override SIP_FACTORY;
290 
292 
301  void beginCommand( const QString &commandText, UndoCommand command = UndoNone );
302 
308  void endCommand();
309 
315  void cancelCommand();
316 
325  virtual void finalizeRestoreFromXml();
326 
327  public slots:
328 
332  void refresh() override;
333 
337  void update();
338 
346  virtual void recalculateFrameSizes();
347 
356  void recalculateFrameRects();
357 
364  virtual void refreshDataDefinedProperty( QgsLayoutObject::DataDefinedProperty property = QgsLayoutObject::AllProperties );
365 
366  signals:
367 
372  void contentsChanged();
373 
374  protected:
375 
384  virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
385 
401  virtual bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context );
402 
403  QList<QgsLayoutFrame *> mFrameItems;
404 
405  ResizeMode mResizeMode = UseExistingFrames;
406 
407  private slots:
408 
412  void handlePageChange();
413 
418  void handleFrameRemoval( QgsLayoutFrame *frame );
419 
420 
421  private:
422  QgsLayoutMultiFrame() = delete;
423 
424  bool mIsRecalculatingSize = false;
425 
426  bool mBlockUpdates = false;
427  bool mBlockUndoCommands = false;
428 
429  QList< QString > mFrameUuids;
430  QList< QString > mFrameTemplateUuids;
431 
433  QString mUuid;
434  QString mTemplateUuid;
435  friend class QgsLayoutFrame;
436  friend class QgsLayout;
437 };
438 
439 
440 #endif // QGSLAYOUTMULTIFRAME_H
QString uuid() const
Returns the multiframe identification string.
The class is used as a container of context for various read/write operations on other objects...
QgsExpressionContext createExpressionContext() const override
Creates an expression context relating to the objects&#39; current state.
virtual QIcon icon() const
Returns the item&#39;s icon.
Base class for graphical items within a QgsLayout.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
Base class for commands to undo/redo layout and layout object changes.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
QList< QgsLayoutFrame * > mFrameItems
int frameCount() const
Returns the number of frames associated with this multiframe.
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...
Repeats the same frame on every page.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_END
Definition: qgis_sip.h:189
A layout table subclass that displays attributes from a vector layer.
#define SIP_FACTORY
Definition: qgis_sip.h:76
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:44
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.
ResizeMode resizeMode() const
Returns the resize mode for the multiframe.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:172
Interface for layout objects which support undo/redo commands.
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.