QGIS API Documentation  3.6.0-Noosa (5873452)
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 
299  void beginCommand( const QString &commandText, UndoCommand command = UndoNone );
300 
306  void endCommand();
307 
313  void cancelCommand();
314 
323  virtual void finalizeRestoreFromXml();
324 
325  public slots:
326 
330  void refresh() override;
331 
335  void update();
336 
344  virtual void recalculateFrameSizes();
345 
354  void recalculateFrameRects();
355 
362  virtual void refreshDataDefinedProperty( QgsLayoutObject::DataDefinedProperty property = QgsLayoutObject::AllProperties );
363 
364  signals:
365 
370  void contentsChanged();
371 
372  protected:
373 
382  virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
383 
399  virtual bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context );
400 
401  QList<QgsLayoutFrame *> mFrameItems;
402 
403  ResizeMode mResizeMode = UseExistingFrames;
404 
405  private slots:
406 
410  void handlePageChange();
411 
416  void handleFrameRemoval( QgsLayoutFrame *frame );
417 
418 
419  private:
420  QgsLayoutMultiFrame() = delete;
421 
422  bool mIsRecalculatingSize = false;
423 
424  bool mBlockUpdates = false;
425  bool mBlockUndoCommands = false;
426 
427  QList< QString > mFrameUuids;
428  QList< QString > mFrameTemplateUuids;
429 
431  QString mUuid;
432  QString mTemplateUuid;
433  friend class QgsLayoutFrame;
434  friend class QgsLayout;
435 };
436 
437 
438 #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...
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:46
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.
#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: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:165
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.