QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 Q_OBJECT
47
48 public:
53
54 ~QgsLayoutPageCollection() override;
55
56 QString stringType() const override { return u"LayoutPageCollection"_s; }
57 QgsLayout *layout() override;
58
64 QList< QgsLayoutItemPage * > pages();
65
70 int pageCount() const;
71
79 QgsLayoutItemPage *page( int pageNumber );
80
89 const QgsLayoutItemPage *page( int pageNumber ) const SIP_SKIP;
90
95 int pageNumber( QgsLayoutItemPage *page ) const;
96
102 QList< QgsLayoutItemPage * > visiblePages( const QRectF &region ) const;
103
109 QList< int > visiblePageNumbers( const QRectF &region ) const;
110
116 bool pageIsEmpty( int page ) const;
117
121 QList< QgsLayoutItem *> itemsOnPage( int page ) const;
122
127 template<class T> void itemsOnPage( QList<T *> &itemList, int page ) const SIP_SKIP
128 {
129 itemList.clear();
130 const QList<QGraphicsItem *> graphicsItemList = mLayout->items();
131 for ( QGraphicsItem *graphicsItem : graphicsItemList )
132 {
133 T *item = dynamic_cast<T *>( graphicsItem );
134 if ( item && item->page() == page )
135 {
136 itemList.push_back( item );
137 }
138 }
139 }
140
149 bool shouldExportPage( int page ) const;
150
162 void addPage( QgsLayoutItemPage *page SIP_TRANSFER );
163
173 QgsLayoutItemPage *extendByNewPage();
174
190 void insertPage( QgsLayoutItemPage *page SIP_TRANSFER, int beforePage );
191
203 void deletePage( int pageNumber );
204
213 void deletePage( QgsLayoutItemPage *page );
214
219 void clear();
220
225
232 void setPageStyleSymbol( QgsFillSymbol *symbol );
233
240 Q_DECL_DEPRECATED const QgsFillSymbol *pageStyleSymbol() const SIP_DEPRECATED;
241
248 void beginPageSizeChange();
249
256 void endPageSizeChange();
257
262 void reflow();
263
270 double maximumPageWidth() const;
271
278 QSizeF maximumPageSize() const;
279
286 bool hasUniformPageSizes() const;
287
302 int pageNumberForPoint( QPointF point ) const;
303
319 int predictPageNumberForPoint( QPointF point ) const;
320
331 QgsLayoutItemPage *pageAtPoint( QPointF point ) const;
332
337 QPointF pagePositionToLayoutPosition( int page, const QgsLayoutPoint &position ) const;
338
343 QgsLayoutPoint pagePositionToAbsolute( int page, const QgsLayoutPoint &position ) const;
344
350 QPointF positionOnPage( QPointF point ) const;
351
355 double spaceBetweenPages() const;
356
360 double pageShadowWidth() const;
361
370 void resizeToContents( const QgsMargins &margins, Qgis::LayoutUnit marginUnits );
371
376 bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
377
382 bool readXml( const QDomElement &collectionElement, const QDomDocument &document, const QgsReadWriteContext &context ) override;
383
387 QgsLayoutGuideCollection &guides();
388
392 SIP_SKIP const QgsLayoutGuideCollection &guides() const;
393
399 void applyPropertiesToAllOtherPages( int sourcePage );
400
401 public slots:
402
406 void redraw();
407
408 signals:
409
413 void changed();
414
422
423 private:
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:62
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:113
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_TRANSFERBACK
Definition qgis_sip.h:47