QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 <memory>
20
21#include "qgis_core.h"
22#include "qgslayoutitempage.h"
24#include "qgslayoutpoint.h"
26
27#include <QAbstractListModel>
28#include <QGraphicsLineItem>
29#include <QPen>
30#include <QSortFilterProxyModel>
31
32class QgsLayout;
34class QDomElement;
35class QDomDocument;
37
43class CORE_EXPORT QgsLayoutGuide : public QObject
44{
45
46 Q_OBJECT
47
48 public:
49
59
60 ~QgsLayoutGuide() override;
61
66 QgsLayout *layout() const;
67
76 void setLayout( QgsLayout *layout );
77
81 Qt::Orientation orientation() const;
82
92
102
109
116
120 void update();
121
125 QGraphicsLineItem *item();
126
131 double layoutPosition() const;
132
137 void setLayoutPosition( double position );
138
139 signals:
140
145
146 private:
147
148 Qt::Orientation mOrientation = Qt::Vertical;
149
151 QgsLayoutMeasurement mPosition;
152
154 QPointer< QgsLayoutItemPage > mPage;
155
156 QPointer< QgsLayout > mLayout;
157
159 QGraphicsLineItem *mLineItem = nullptr;
160
161};
162
168class CORE_EXPORT QgsLayoutGuideCollection : public QAbstractTableModel, public QgsLayoutSerializableObject
169{
170
171 Q_OBJECT
172
173 public:
174
176
177 // *INDENT-OFF*
178
186 {
187 Orientation SIP_MONKEYPATCH_COMPAT_NAME(OrientationRole) = Qt::UserRole,
188 Position SIP_MONKEYPATCH_COMPAT_NAME(PositionRole),
191 LayoutPosition SIP_MONKEYPATCH_COMPAT_NAME(LayoutPositionRole),
192 };
193 Q_ENUM( CustomRole )
194 // *INDENT-ON*
195
196
201 ~QgsLayoutGuideCollection() override;
202
203 QString stringType() const override { return QStringLiteral( "LayoutGuideCollection" ); }
204 QgsLayout *layout() override;
205
206 int rowCount( const QModelIndex & ) const override;
207 int columnCount( const QModelIndex & ) const override;
208 QVariant data( const QModelIndex &index, int role ) const override;
209 bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
210 Qt::ItemFlags flags( const QModelIndex &index ) const override;
211 QVariant headerData( int section, Qt::Orientation orientation,
212 int role = Qt::DisplayRole ) const override;
213 bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
214
220 void addGuide( QgsLayoutGuide *guide SIP_TRANSFER );
221
226 void removeGuide( QgsLayoutGuide *guide );
227
231 void setGuideLayoutPosition( QgsLayoutGuide *guide, double position );
232
237 void clear();
238
242 void applyGuidesToAllOtherPages( int sourcePage );
243
247 void update();
248
252 QList< QgsLayoutGuide * > guides();
253
260 QList< QgsLayoutGuide * > guides( Qt::Orientation orientation, int page = -1 );
261
266 QList< QgsLayoutGuide * > guidesOnPage( int page );
267
272 bool visible() const;
273
278 void setVisible( bool visible );
279
284 bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
285
290 bool readXml( const QDomElement &collectionElement, const QDomDocument &document, const QgsReadWriteContext &context ) override;
291
292 private slots:
293
294 void pageAboutToBeRemoved( int pageNumber );
295
296 private:
297
298 enum UndoRoles
299 {
300 Move = 10000,
301 Remove = 20000,
302 };
303
304 QgsLayout *mLayout = nullptr;
305 QgsLayoutPageCollection *mPageCollection = nullptr;
306
307 QList< QgsLayoutGuide * > mGuides;
308 int mHeaderSize = 0;
309
310 bool mGuidesVisible = true;
311 bool mBlockUndoCommands = false;
312
314
315};
316
317
323class CORE_EXPORT QgsLayoutGuideProxyModel : public QSortFilterProxyModel
324{
325 Q_OBJECT
326
327 public:
328
334 explicit QgsLayoutGuideProxyModel( QObject *parent SIP_TRANSFERTHIS, Qt::Orientation orientation, int page );
335
339 void setPage( int page );
340
341 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
342 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
343
344 private:
345 Qt::Orientation mOrientation = Qt::Horizontal;
346 int mPage = 0;
347
348};
349
350#endif //QGSLAYOUTGUIDECOLLECTION_H
Stores and manages the snap guides used by a layout.
QString stringType() const override
Returns the object type as a string.
QgsLayoutGuideCollection(QgsLayout *layout, QgsLayoutPageCollection *pageCollection)
Constructor for QgsLayoutGuideCollection belonging to the specified layout, and linked to the specifi...
void setPage(int page)
Sets the current page for filtering matching guides.
QgsLayoutGuideProxyModel(QObject *parent, Qt::Orientation orientation, int page)
Constructor for QgsLayoutGuideProxyModel, filtered to guides of the specified orientation and page on...
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
Contains the configuration for a single snap guide used by a layout.
QgsLayoutMeasurement position() const
Returns the guide's position within the page.
QgsLayoutItemPage * page()
Returns the page the guide is contained within.
Qt::Orientation orientation() const
Returns the guide's orientation.
QgsLayout * layout() const
Returns the layout the guide belongs to.
void setLayout(QgsLayout *layout)
Sets the layout the guide belongs to.
void setLayoutPosition(double position)
Sets the guide's position in absolute layout units.
void setPage(QgsLayoutItemPage *page)
Sets the page the guide is contained within.
void setPosition(QgsLayoutMeasurement position)
Sets the guide's position within the page.
QgsLayoutGuide(Qt::Orientation orientation, QgsLayoutMeasurement position, QgsLayoutItemPage *page)
Constructor for a new guide with the specified orientation and initial position.
double layoutPosition() const
Returns the guide's position in absolute layout units.
void positionChanged()
Emitted when the guide's position is changed.
void update()
Updates the position of the guide's line item.
QGraphicsLineItem * item()
Returns the guide's line item.
Item representing the paper in a layout.
Provides a method of storing measurements for use in QGIS layouts using a variety of different measur...
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:50
A container for the context for various read/write operations on objects.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:268
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:270