QGIS API Documentation 3.99.0-Master (d270888f95f)
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#include <QString>
32
33using namespace Qt::StringLiterals;
34
35class QgsLayout;
37class QDomElement;
38class QDomDocument;
40
46class CORE_EXPORT QgsLayoutGuide : public QObject
47{
48
49 Q_OBJECT
50
51 public:
52
62
63 ~QgsLayoutGuide() override;
64
69 QgsLayout *layout() const;
70
79 void setLayout( QgsLayout *layout );
80
84 Qt::Orientation orientation() const;
85
95
105
112
119
123 void update();
124
128 QGraphicsLineItem *item();
129
134 double layoutPosition() const;
135
140 void setLayoutPosition( double position );
141
142 signals:
143
148
149 private:
150
151 Qt::Orientation mOrientation = Qt::Vertical;
152
154 QgsLayoutMeasurement mPosition;
155
157 QPointer< QgsLayoutItemPage > mPage;
158
159 QPointer< QgsLayout > mLayout;
160
162 QGraphicsLineItem *mLineItem = nullptr;
163
164};
165
171class CORE_EXPORT QgsLayoutGuideCollection : public QAbstractTableModel, public QgsLayoutSerializableObject
172{
173
174 Q_OBJECT
175
176 public:
177
179
180 // *INDENT-OFF*
181
189 {
190 Orientation SIP_MONKEYPATCH_COMPAT_NAME(OrientationRole) = Qt::UserRole,
191 Position SIP_MONKEYPATCH_COMPAT_NAME(PositionRole),
194 LayoutPosition SIP_MONKEYPATCH_COMPAT_NAME(LayoutPositionRole),
195 };
196 Q_ENUM( CustomRole )
197 // *INDENT-ON*
198
199
204 ~QgsLayoutGuideCollection() override;
205
206 QString stringType() const override { return u"LayoutGuideCollection"_s; }
207 QgsLayout *layout() override;
208
209 int rowCount( const QModelIndex & ) const override;
210 int columnCount( const QModelIndex & ) const override;
211 QVariant data( const QModelIndex &index, int role ) const override;
212 bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
213 Qt::ItemFlags flags( const QModelIndex &index ) const override;
214 QVariant headerData( int section, Qt::Orientation orientation,
215 int role = Qt::DisplayRole ) const override;
216 bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
217
223 void addGuide( QgsLayoutGuide *guide SIP_TRANSFER );
224
229 void removeGuide( QgsLayoutGuide *guide );
230
234 void setGuideLayoutPosition( QgsLayoutGuide *guide, double position );
235
240 void clear();
241
245 void applyGuidesToAllOtherPages( int sourcePage );
246
250 void update();
251
255 QList< QgsLayoutGuide * > guides();
256
263 QList< QgsLayoutGuide * > guides( Qt::Orientation orientation, int page = -1 );
264
269 QList< QgsLayoutGuide * > guidesOnPage( int page );
270
275 bool visible() const;
276
281 void setVisible( bool visible );
282
287 bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
288
293 bool readXml( const QDomElement &collectionElement, const QDomDocument &document, const QgsReadWriteContext &context ) override;
294
295 private slots:
296
297 void pageAboutToBeRemoved( int pageNumber );
298
299 private:
300
301 enum UndoRoles
302 {
303 Move = 10000,
304 Remove = 20000,
305 };
306
307 QgsLayout *mLayout = nullptr;
308 QgsLayoutPageCollection *mPageCollection = nullptr;
309
310 QList< QgsLayoutGuide * > mGuides;
311 int mHeaderSize = 0;
312
313 bool mGuidesVisible = true;
314 bool mBlockUndoCommands = false;
315
317
318};
319
320
326class CORE_EXPORT QgsLayoutGuideProxyModel : public QSortFilterProxyModel
327{
328 Q_OBJECT
329
330 public:
331
337 explicit QgsLayoutGuideProxyModel( QObject *parent SIP_TRANSFERTHIS, Qt::Orientation orientation, int page );
338
342 void setPage( int page );
343
344 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
345 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
346
347 private:
348 Qt::Orientation mOrientation = Qt::Horizontal;
349 int mPage = 0;
350
351};
352
353#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