QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
32class QgsLayout;
34class QgsMargins;
35
41class CORE_EXPORT QgsLayoutPageCollection : public QObject, public QgsLayoutSerializableObject
42{
43
44 Q_OBJECT
45
46 public:
47
52
53 ~QgsLayoutPageCollection() override;
54
55 QString stringType() const override { return QStringLiteral( "LayoutPageCollection" ); }
56 QgsLayout *layout() override;
57
63 QList< QgsLayoutItemPage * > pages();
64
69 int pageCount() const;
70
78 QgsLayoutItemPage *page( int pageNumber );
79
88 const QgsLayoutItemPage *page( int pageNumber ) const SIP_SKIP;
89
94 int pageNumber( QgsLayoutItemPage *page ) const;
95
101 QList< QgsLayoutItemPage * > visiblePages( const QRectF &region ) const;
102
108 QList< int > visiblePageNumbers( const QRectF &region ) const;
109
115 bool pageIsEmpty( int page ) const;
116
120 QList< QgsLayoutItem *> itemsOnPage( int page ) const;
121
126 template<class T> void itemsOnPage( QList<T *> &itemList, int page ) const SIP_SKIP
127 {
128 itemList.clear();
129 const QList<QGraphicsItem *> graphicsItemList = mLayout->items();
130 for ( QGraphicsItem *graphicsItem : graphicsItemList )
131 {
132 T *item = dynamic_cast<T *>( graphicsItem );
133 if ( item && item->page() == page )
134 {
135 itemList.push_back( item );
136 }
137 }
138 }
139
148 bool shouldExportPage( int page ) const;
149
161 void addPage( QgsLayoutItemPage *page SIP_TRANSFER );
162
172 QgsLayoutItemPage *extendByNewPage();
173
189 void insertPage( QgsLayoutItemPage *page SIP_TRANSFER, int beforePage );
190
202 void deletePage( int pageNumber );
203
212 void deletePage( QgsLayoutItemPage *page );
213
218 void clear();
219
224
231 void setPageStyleSymbol( QgsFillSymbol *symbol );
232
239 Q_DECL_DEPRECATED const QgsFillSymbol *pageStyleSymbol() const SIP_DEPRECATED;
240
247 void beginPageSizeChange();
248
255 void endPageSizeChange();
256
261 void reflow();
262
269 double maximumPageWidth() const;
270
277 QSizeF maximumPageSize() const;
278
285 bool hasUniformPageSizes() const;
286
301 int pageNumberForPoint( QPointF point ) const;
302
318 int predictPageNumberForPoint( QPointF point ) const;
319
330 QgsLayoutItemPage *pageAtPoint( QPointF point ) const;
331
336 QPointF pagePositionToLayoutPosition( int page, const QgsLayoutPoint &position ) const;
337
342 QgsLayoutPoint pagePositionToAbsolute( int page, const QgsLayoutPoint &position ) const;
343
349 QPointF positionOnPage( QPointF point ) const;
350
354 double spaceBetweenPages() const;
355
359 double pageShadowWidth() const;
360
369 void resizeToContents( const QgsMargins &margins, Qgis::LayoutUnit marginUnits );
370
375 bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
376
381 bool readXml( const QDomElement &collectionElement, const QDomDocument &document, const QgsReadWriteContext &context ) override;
382
386 QgsLayoutGuideCollection &guides();
387
391 SIP_SKIP const QgsLayoutGuideCollection &guides() const;
392
398 void applyPropertiesToAllOtherPages( int sourcePage );
399
400 public slots:
401
405 void redraw();
406
407 signals:
408
412 void changed();
413
421
422 private:
423
424 QgsLayout *mLayout = nullptr;
425
426 std::unique_ptr< QgsLayoutGuideCollection > mGuideCollection;
427
429 std::unique_ptr< QgsFillSymbol > mPageStyleSymbol;
430
431 QList< QgsLayoutItemPage * > mPages;
432
433 bool mBlockUndoCommands = false;
434
435 QMap< QString, QPair< int, QgsLayoutPoint > > mPreviousItemPositions;
436
437 void createDefaultPageStyleSymbol();
438
440};
441
442#endif //QGSLAYOUTPAGECOLLECTION_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:56
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:38
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