QGIS API Documentation 3.99.0-Master (357b655ed83)
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 <memory>
21
22#include "qgis_core.h"
23#include "qgis_sip.h"
24#include "qgslayout.h"
25#include "qgslayoutitem.h"
26#include "qgslayoutitempage.h"
27#include "qgslayoutpoint.h"
29
30#include <QObject>
31#include <QString>
32
33using namespace Qt::StringLiterals;
34
35class QgsLayout;
37class QgsMargins;
38
44class CORE_EXPORT QgsLayoutPageCollection : public QObject, public QgsLayoutSerializableObject
45{
46
47 Q_OBJECT
48
49 public:
50
55
56 ~QgsLayoutPageCollection() override;
57
58 QString stringType() const override { return u"LayoutPageCollection"_s; }
59 QgsLayout *layout() override;
60
66 QList< QgsLayoutItemPage * > pages();
67
72 int pageCount() const;
73
81 QgsLayoutItemPage *page( int pageNumber );
82
91 const QgsLayoutItemPage *page( int pageNumber ) const SIP_SKIP;
92
97 int pageNumber( QgsLayoutItemPage *page ) const;
98
104 QList< QgsLayoutItemPage * > visiblePages( const QRectF &region ) const;
105
111 QList< int > visiblePageNumbers( const QRectF &region ) const;
112
118 bool pageIsEmpty( int page ) const;
119
123 QList< QgsLayoutItem *> itemsOnPage( int page ) const;
124
129 template<class T> void itemsOnPage( QList<T *> &itemList, int page ) const SIP_SKIP
130 {
131 itemList.clear();
132 const QList<QGraphicsItem *> graphicsItemList = mLayout->items();
133 for ( QGraphicsItem *graphicsItem : graphicsItemList )
134 {
135 T *item = dynamic_cast<T *>( graphicsItem );
136 if ( item && item->page() == page )
137 {
138 itemList.push_back( item );
139 }
140 }
141 }
142
151 bool shouldExportPage( int page ) const;
152
164 void addPage( QgsLayoutItemPage *page SIP_TRANSFER );
165
175 QgsLayoutItemPage *extendByNewPage();
176
192 void insertPage( QgsLayoutItemPage *page SIP_TRANSFER, int beforePage );
193
205 void deletePage( int pageNumber );
206
215 void deletePage( QgsLayoutItemPage *page );
216
221 void clear();
222
227
234 void setPageStyleSymbol( QgsFillSymbol *symbol );
235
242 Q_DECL_DEPRECATED const QgsFillSymbol *pageStyleSymbol() const SIP_DEPRECATED;
243
250 void beginPageSizeChange();
251
258 void endPageSizeChange();
259
264 void reflow();
265
272 double maximumPageWidth() const;
273
280 QSizeF maximumPageSize() const;
281
288 bool hasUniformPageSizes() const;
289
304 int pageNumberForPoint( QPointF point ) const;
305
321 int predictPageNumberForPoint( QPointF point ) const;
322
333 QgsLayoutItemPage *pageAtPoint( QPointF point ) const;
334
339 QPointF pagePositionToLayoutPosition( int page, const QgsLayoutPoint &position ) const;
340
345 QgsLayoutPoint pagePositionToAbsolute( int page, const QgsLayoutPoint &position ) const;
346
352 QPointF positionOnPage( QPointF point ) const;
353
357 double spaceBetweenPages() const;
358
362 double pageShadowWidth() const;
363
372 void resizeToContents( const QgsMargins &margins, Qgis::LayoutUnit marginUnits );
373
378 bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
379
384 bool readXml( const QDomElement &collectionElement, const QDomDocument &document, const QgsReadWriteContext &context ) override;
385
389 QgsLayoutGuideCollection &guides();
390
394 SIP_SKIP const QgsLayoutGuideCollection &guides() const;
395
401 void applyPropertiesToAllOtherPages( int sourcePage );
402
403 public slots:
404
408 void redraw();
409
410 signals:
411
415 void changed();
416
424
425 private:
426
427 QgsLayout *mLayout = nullptr;
428
429 std::unique_ptr< QgsLayoutGuideCollection > mGuideCollection;
430
432 std::unique_ptr< QgsFillSymbol > mPageStyleSymbol;
433
434 QList< QgsLayoutItemPage * > mPages;
435
436 bool mBlockUndoCommands = false;
437
438 QMap< QString, QPair< int, QgsLayoutPoint > > mPreviousItemPositions;
439
440 void createDefaultPageStyleSymbol();
441
443};
444
445#endif //QGSLAYOUTPAGECOLLECTION_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:59
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.
void changed()
Emitted when pages are added or removed from the collection.
void itemsOnPage(QList< T * > &itemList, int page) const
Returns layout items of a specific type on a specified page.
QgsLayoutPageCollection(QgsLayout *layout)
Constructor for QgsLayoutItemPage, with the specified parent layout.
QgsLayout * layout() override
Returns the layout the object belongs to.
void pageAboutToBeRemoved(int pageNumber)
Emitted just before a page is removed from the collection.
QgsLayoutItemPage * page(int pageNumber)
Returns a specific page (by pageNumber) from the collection.
int pageNumber(QgsLayoutItemPage *page) const
Returns the page number for the specified page, or -1 if the page is not contained in the collection.
QString stringType() const override
Returns the object type as a string.
Provides a method of storing points, consisting of an x and y coordinate, for use in QGIS layouts.
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:50
Defines the four margins of a rectangle.
Definition qgsmargins.h:40
A container for the context for various read/write operations on objects.
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_TRANSFERBACK
Definition qgis_sip.h:48