QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
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 "qgslayout.h"
23#include "qgslayoutitempage.h"
24#include "qgslayoutitem.h"
26#include "qgslayoutpoint.h"
27#include <QObject>
28#include <memory>
29
30class QgsLayout;
32class QgsMargins;
33
39class CORE_EXPORT QgsLayoutPageCollection : public QObject, public QgsLayoutSerializableObject
40{
41
42 Q_OBJECT
43
44 public:
45
50
51 ~QgsLayoutPageCollection() override;
52
53 QString stringType() const override { return QStringLiteral( "LayoutPageCollection" ); }
54 QgsLayout *layout() override;
55
61 QList< QgsLayoutItemPage * > pages();
62
67 int pageCount() const;
68
76 QgsLayoutItemPage *page( int pageNumber );
77
86 const QgsLayoutItemPage *page( int pageNumber ) const SIP_SKIP;
87
92 int pageNumber( QgsLayoutItemPage *page ) const;
93
99 QList< QgsLayoutItemPage * > visiblePages( const QRectF &region ) const;
100
106 QList< int > visiblePageNumbers( const QRectF &region ) const;
107
113 bool pageIsEmpty( int page ) const;
114
118 QList< QgsLayoutItem *> itemsOnPage( int page ) const;
119
124 template<class T> void itemsOnPage( QList<T *> &itemList, int page ) const SIP_SKIP
125 {
126 itemList.clear();
127 const QList<QGraphicsItem *> graphicsItemList = mLayout->items();
128 for ( QGraphicsItem *graphicsItem : graphicsItemList )
129 {
130 T *item = dynamic_cast<T *>( graphicsItem );
131 if ( item && item->page() == page )
132 {
133 itemList.push_back( item );
134 }
135 }
136 }
137
146 bool shouldExportPage( int page ) const;
147
159 void addPage( QgsLayoutItemPage *page SIP_TRANSFER );
160
170 QgsLayoutItemPage *extendByNewPage();
171
187 void insertPage( QgsLayoutItemPage *page SIP_TRANSFER, int beforePage );
188
200 void deletePage( int pageNumber );
201
210 void deletePage( QgsLayoutItemPage *page );
211
216 void clear();
217
222
229 void setPageStyleSymbol( QgsFillSymbol *symbol );
230
237 Q_DECL_DEPRECATED const QgsFillSymbol *pageStyleSymbol() const SIP_DEPRECATED;
238
245 void beginPageSizeChange();
246
253 void endPageSizeChange();
254
259 void reflow();
260
267 double maximumPageWidth() const;
268
275 QSizeF maximumPageSize() const;
276
283 bool hasUniformPageSizes() const;
284
299 int pageNumberForPoint( QPointF point ) const;
300
316 int predictPageNumberForPoint( QPointF point ) const;
317
328 QgsLayoutItemPage *pageAtPoint( QPointF point ) const;
329
334 QPointF pagePositionToLayoutPosition( int page, const QgsLayoutPoint &position ) const;
335
340 QgsLayoutPoint pagePositionToAbsolute( int page, const QgsLayoutPoint &position ) const;
341
347 QPointF positionOnPage( QPointF point ) const;
348
352 double spaceBetweenPages() const;
353
357 double pageShadowWidth() const;
358
367 void resizeToContents( const QgsMargins &margins, Qgis::LayoutUnit marginUnits );
368
373 bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
374
379 bool readXml( const QDomElement &collectionElement, const QDomDocument &document, const QgsReadWriteContext &context ) override;
380
384 QgsLayoutGuideCollection &guides();
385
389 SIP_SKIP const QgsLayoutGuideCollection &guides() const;
390
396 void applyPropertiesToAllOtherPages( int sourcePage );
397
398 public slots:
399
403 void redraw();
404
405 signals:
406
410 void changed();
411
418 void pageAboutToBeRemoved( int pageNumber );
419
420 private:
421
422 QgsLayout *mLayout = nullptr;
423
424 std::unique_ptr< QgsLayoutGuideCollection > mGuideCollection;
425
427 std::unique_ptr< QgsFillSymbol > mPageStyleSymbol;
428
429 QList< QgsLayoutItemPage * > mPages;
430
431 bool mBlockUndoCommands = false;
432
433 QMap< QString, QPair< int, QgsLayoutPoint > > mPreviousItemPositions;
434
435 void createDefaultPageStyleSymbol();
436
437 friend class QgsLayoutPageCollectionUndoCommand;
438};
439
440#endif //QGSLAYOUTPAGECOLLECTION_H
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Stores and manages the snap guides used by a layout.
Item representing the paper in a layout.
A manager for a collection of pages in a layout.
void itemsOnPage(QList< T * > &itemList, int page) const
Returns layout items of a specific type on a specified page.
QString stringType() const override
Returns the object type as a string.
This class provides a method of storing points, consisting of an x and y coordinate,...
An interface for layout objects which can be stored and read from DOM elements.
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
The QgsMargins class defines the four margins of a rectangle.
Definition qgsmargins.h:37
The class is used as a container of context for various read/write operations on other objects.
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_TRANSFERBACK
Definition qgis_sip.h:48