QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
qgslayoutguidecollection.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutguidecollection.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#ifndef QGSLAYOUTGUIDECOLLECTION_H
17#define QGSLAYOUTGUIDECOLLECTION_H
18
19#include "qgis_core.h"
21#include "qgslayoutpoint.h"
22#include "qgslayoutitempage.h"
24#include <QPen>
25#include <QAbstractListModel>
26#include <QSortFilterProxyModel>
27#include <QGraphicsLineItem>
28#include <memory>
29
30class QgsLayout;
32class QDomElement;
33class QDomDocument;
35
41class CORE_EXPORT QgsLayoutGuide : public QObject
42{
43
44 Q_OBJECT
45
46 public:
47
56 QgsLayoutGuide( Qt::Orientation orientation, QgsLayoutMeasurement position, QgsLayoutItemPage *page );
57
58 ~QgsLayoutGuide() override;
59
64 QgsLayout *layout() const;
65
74 void setLayout( QgsLayout *layout );
75
79 Qt::Orientation orientation() const;
80
89 QgsLayoutMeasurement position() const;
90
99 void setPosition( QgsLayoutMeasurement position );
100
106 QgsLayoutItemPage *page();
107
113 void setPage( QgsLayoutItemPage *page );
114
118 void update();
119
123 QGraphicsLineItem *item();
124
129 double layoutPosition() const;
130
135 void setLayoutPosition( double position );
136
137 signals:
138
143
144 private:
145
146 Qt::Orientation mOrientation = Qt::Vertical;
147
149 QgsLayoutMeasurement mPosition;
150
152 QPointer< QgsLayoutItemPage > mPage;
153
154 QPointer< QgsLayout > mLayout;
155
157 QGraphicsLineItem *mLineItem = nullptr;
158
159};
160
166class CORE_EXPORT QgsLayoutGuideCollection : public QAbstractTableModel, public QgsLayoutSerializableObject
167{
168
169 Q_OBJECT
170
171 public:
172
174
175 // *INDENT-OFF*
176
184 {
185 Orientation SIP_MONKEYPATCH_COMPAT_NAME(OrientationRole) = Qt::UserRole,
186 Position SIP_MONKEYPATCH_COMPAT_NAME(PositionRole),
187 Units SIP_MONKEYPATCH_COMPAT_NAME(UnitsRole),
188 Page SIP_MONKEYPATCH_COMPAT_NAME(PageRole),
189 LayoutPosition SIP_MONKEYPATCH_COMPAT_NAME(LayoutPositionRole),
190 };
191 Q_ENUM( CustomRole )
192 // *INDENT-ON*
193
194
199 ~QgsLayoutGuideCollection() override;
200
201 QString stringType() const override { return QStringLiteral( "LayoutGuideCollection" ); }
202 QgsLayout *layout() override;
203
204 int rowCount( const QModelIndex & ) const override;
205 int columnCount( const QModelIndex & ) const override;
206 QVariant data( const QModelIndex &index, int role ) const override;
207 bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
208 Qt::ItemFlags flags( const QModelIndex &index ) const override;
209 QVariant headerData( int section, Qt::Orientation orientation,
210 int role = Qt::DisplayRole ) const override;
211 bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
212
218 void addGuide( QgsLayoutGuide *guide SIP_TRANSFER );
219
224 void removeGuide( QgsLayoutGuide *guide );
225
229 void setGuideLayoutPosition( QgsLayoutGuide *guide, double position );
230
235 void clear();
236
240 void applyGuidesToAllOtherPages( int sourcePage );
241
245 void update();
246
250 QList< QgsLayoutGuide * > guides();
251
258 QList< QgsLayoutGuide * > guides( Qt::Orientation orientation, int page = -1 );
259
264 QList< QgsLayoutGuide * > guidesOnPage( int page );
265
270 bool visible() const;
271
276 void setVisible( bool visible );
277
282 bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
283
288 bool readXml( const QDomElement &collectionElement, const QDomDocument &document, const QgsReadWriteContext &context ) override;
289
290 private slots:
291
292 void pageAboutToBeRemoved( int pageNumber );
293
294 private:
295
296 enum UndoRoles
297 {
298 Move = 10000,
299 Remove = 20000,
300 };
301
302 QgsLayout *mLayout = nullptr;
303 QgsLayoutPageCollection *mPageCollection = nullptr;
304
305 QList< QgsLayoutGuide * > mGuides;
306 int mHeaderSize = 0;
307
308 bool mGuidesVisible = true;
309 bool mBlockUndoCommands = false;
310
311 friend class QgsLayoutGuideCollectionUndoCommand;
312
313};
314
315
321class CORE_EXPORT QgsLayoutGuideProxyModel : public QSortFilterProxyModel
322{
323 Q_OBJECT
324
325 public:
326
332 explicit QgsLayoutGuideProxyModel( QObject *parent SIP_TRANSFERTHIS, Qt::Orientation orientation, int page );
333
337 void setPage( int page );
338
339 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
340 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
341
342 private:
343 Qt::Orientation mOrientation = Qt::Horizontal;
344 int mPage = 0;
345
346};
347
348#endif //QGSLAYOUTGUIDECOLLECTION_H
Stores and manages the snap guides used by a layout.
QString stringType() const override
Returns the object type as a string.
Filters QgsLayoutGuideCollection models to guides of a single orientation (horizontal or vertical).
Contains the configuration for a single snap guide used by a layout.
void positionChanged()
Emitted when the guide's position is changed.
Item representing the paper in a layout.
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
A manager for a collection of pages in a layout.
An interface for layout objects which can be stored and read from DOM elements.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:49
The class is used as a container of context for various read/write operations on other objects.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:271
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:273