QGIS API Documentation  3.6.0-Noosa (5873452)
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( const QRectF &region ) const;
101 
107  QList< int > visiblePageNumbers( const 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 
147  bool shouldExportPage( int page ) const;
148 
160  void addPage( QgsLayoutItemPage *page SIP_TRANSFER );
161 
171  QgsLayoutItemPage *extendByNewPage();
172 
188  void insertPage( QgsLayoutItemPage *page SIP_TRANSFER, int beforePage );
189 
201  void deletePage( int pageNumber );
202 
211  void deletePage( QgsLayoutItemPage *page );
212 
217  void clear();
218 
223 
230  void setPageStyleSymbol( QgsFillSymbol *symbol );
231 
236  const QgsFillSymbol *pageStyleSymbol() const { return mPageStyleSymbol.get(); }
237 
244  void beginPageSizeChange();
245 
252  void endPageSizeChange();
253 
258  void reflow();
259 
266  double maximumPageWidth() const;
267 
274  QSizeF maximumPageSize() const;
275 
282  bool hasUniformPageSizes() const;
283 
298  int pageNumberForPoint( QPointF point ) const;
299 
315  int predictPageNumberForPoint( QPointF point ) const;
316 
327  QgsLayoutItemPage *pageAtPoint( QPointF point ) const;
328 
333  QPointF pagePositionToLayoutPosition( int page, const QgsLayoutPoint &position ) const;
334 
339  QgsLayoutPoint pagePositionToAbsolute( int page, const QgsLayoutPoint &position ) const;
340 
346  QPointF positionOnPage( QPointF point ) const;
347 
351  double spaceBetweenPages() const;
352 
356  double pageShadowWidth() const;
357 
366  void resizeToContents( const QgsMargins &margins, QgsUnitTypes::LayoutUnit marginUnits );
367 
372  bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
373 
378  bool readXml( const QDomElement &collectionElement, const QDomDocument &document, const QgsReadWriteContext &context ) override;
379 
383  QgsLayoutGuideCollection &guides();
384 
388  SIP_SKIP const QgsLayoutGuideCollection &guides() const;
389 
390  public slots:
391 
395  void redraw();
396 
397  signals:
398 
402  void changed();
403 
410  void pageAboutToBeRemoved( int pageNumber );
411 
412  private:
413 
414  QgsLayout *mLayout = nullptr;
415 
416  std::unique_ptr< QgsLayoutGuideCollection > mGuideCollection;
417 
419  std::unique_ptr< QgsFillSymbol > mPageStyleSymbol;
420 
421  QList< QgsLayoutItemPage * > mPages;
422 
423  bool mBlockUndoCommands = false;
424 
425  QMap< QString, QPair< int, QgsLayoutPoint > > mPreviousItemPositions;
426 
427  void createDefaultPageStyleSymbol();
428 
429  friend class QgsLayoutPageCollectionUndoCommand;
430 };
431 
432 #endif //QGSLAYOUTPAGECOLLECTION_H
The class is used as a container of context for various read/write operations on other objects...
QString stringType() const override
Returns 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:125
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgssymbol.h:1003
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.