QGIS API Documentation  3.0.2-Girona (307d082)
qgslayoutpagecollection.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutpagecollection.h
3  --------------------------
4  begin : July 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #ifndef QGSLAYOUTPAGECOLLECTION_H
18 #define QGSLAYOUTPAGECOLLECTION_H
19 
20 #include "qgis_core.h"
21 #include "qgis_sip.h"
22 #include "qgssymbol.h"
23 #include "qgslayout.h"
24 #include "qgslayoutitempage.h"
25 #include "qgslayoutitem.h"
27 #include "qgslayoutpoint.h"
28 #include <QObject>
29 #include <memory>
30 
31 class QgsLayout;
33 
40 class CORE_EXPORT QgsLayoutPageCollection : public QObject, public QgsLayoutSerializableObject
41 {
42 
43  Q_OBJECT
44 
45  public:
46 
51 
52  ~QgsLayoutPageCollection() override;
53 
54  QString stringType() const override { return QStringLiteral( "LayoutPageCollection" ); }
55  QgsLayout *layout() override;
56 
62  QList< QgsLayoutItemPage * > pages();
63 
68  int pageCount() const;
69 
77  QgsLayoutItemPage *page( int pageNumber );
78 
87  const QgsLayoutItemPage *page( int pageNumber ) const SIP_SKIP;
88 
93  int pageNumber( QgsLayoutItemPage *page ) const;
94 
100  QList< QgsLayoutItemPage * > visiblePages( QRectF region ) const;
101 
107  QList< int > visiblePageNumbers( QRectF region ) const;
108 
114  bool pageIsEmpty( int page ) const;
115 
119  QList< QgsLayoutItem *> itemsOnPage( int page ) const;
120 
125  template<class T> void itemsOnPage( QList<T *> &itemList, int page ) const SIP_SKIP
126  {
127  itemList.clear();
128  const QList<QGraphicsItem *> graphicsItemList = mLayout->items();
129  for ( QGraphicsItem *graphicsItem : graphicsItemList )
130  {
131  T *item = dynamic_cast<T *>( graphicsItem );
132  if ( item && item->page() == page )
133  {
134  itemList.push_back( item );
135  }
136  }
137  }
138 
143  bool shouldExportPage( int page ) const;
144 
156  void addPage( QgsLayoutItemPage *page SIP_TRANSFER );
157 
167  QgsLayoutItemPage *extendByNewPage();
168 
184  void insertPage( QgsLayoutItemPage *page SIP_TRANSFER, int beforePage );
185 
197  void deletePage( int pageNumber );
198 
207  void deletePage( QgsLayoutItemPage *page );
208 
213  void clear();
214 
219 
226  void setPageStyleSymbol( QgsFillSymbol *symbol );
227 
232  const QgsFillSymbol *pageStyleSymbol() const { return mPageStyleSymbol.get(); }
233 
240  void beginPageSizeChange();
241 
248  void endPageSizeChange();
249 
254  void reflow();
255 
262  double maximumPageWidth() const;
263 
270  QSizeF maximumPageSize() const;
271 
278  bool hasUniformPageSizes() const;
279 
294  int pageNumberForPoint( QPointF point ) const;
295 
311  int predictPageNumberForPoint( QPointF point ) const;
312 
323  QgsLayoutItemPage *pageAtPoint( QPointF point ) const;
324 
329  QPointF pagePositionToLayoutPosition( int page, const QgsLayoutPoint &position ) const;
330 
335  QgsLayoutPoint pagePositionToAbsolute( int page, const QgsLayoutPoint &position ) const;
336 
342  QPointF positionOnPage( QPointF point ) const;
343 
347  double spaceBetweenPages() const;
348 
352  double pageShadowWidth() const;
353 
362  void resizeToContents( const QgsMargins &margins, QgsUnitTypes::LayoutUnit marginUnits );
363 
368  bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
369 
374  bool readXml( const QDomElement &collectionElement, const QDomDocument &document, const QgsReadWriteContext &context ) override;
375 
379  QgsLayoutGuideCollection &guides();
380 
384  SIP_SKIP const QgsLayoutGuideCollection &guides() const;
385 
386  public slots:
387 
391  void redraw();
392 
393  signals:
394 
398  void changed();
399 
406  void pageAboutToBeRemoved( int pageNumber );
407 
408  private:
409 
410  QgsLayout *mLayout = nullptr;
411 
412  std::unique_ptr< QgsLayoutGuideCollection > mGuideCollection;
413 
415  std::unique_ptr< QgsFillSymbol > mPageStyleSymbol;
416 
417  QList< QgsLayoutItemPage * > mPages;
418 
419  bool mBlockUndoCommands = false;
420 
421  QMap< QString, QPair< int, QgsLayoutPoint > > mPreviousItemPositions;
422 
423  void createDefaultPageStyleSymbol();
424 
425  friend class QgsLayoutPageCollectionUndoCommand;
426 };
427 
428 #endif //QGSLAYOUTPAGECOLLECTION_H
The class is used as a container of context for various read/write operations on other objects...
QString stringType() const override
Return the object type as a string.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
virtual bool writeXml(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const =0
Stores the objects&#39;s state in a DOM element.
const QgsFillSymbol * pageStyleSymbol() const
Returns the symbol to use for drawing pages in the collection.
#define SIP_TRANSFERBACK
Definition: qgis_sip.h:41
This class provides a method of storing points, consisting of an x and y coordinate, for use in QGIS layouts.
#define SIP_SKIP
Definition: qgis_sip.h:119
void itemsOnPage(QList< T *> &itemList, int page) const
Returns layout items of a specific type on a specified page.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
Stores and manages the snap guides used by a layout.
virtual QgsLayout * layout()=0
Returns the layout the object belongs to.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
A manager for a collection of pages in a layout.
An interface for layout objects which can be stored and read from DOM elements.
LayoutUnit
Layout measurement units.
Definition: qgsunittypes.h:114
virtual bool readXml(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)=0
Sets the objects&#39;s state from a DOM element.
The QgsMargins class defines the four margins of a rectangle.
Definition: qgsmargins.h:37
Item representing the paper in a layout.