QGIS API Documentation 4.1.0-Master (60fea48833c)
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 Q_OBJECT
49
50 public:
60
61 ~QgsLayoutGuide() override;
62
67 QgsLayout *layout() const;
68
77 void setLayout( QgsLayout *layout );
78
82 Qt::Orientation orientation() const;
83
93
103
110
117
121 void update();
122
126 QGraphicsLineItem *item();
127
132 double layoutPosition() const;
133
138 void setLayoutPosition( double position );
139
140 signals:
141
146
147 private:
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
167class CORE_EXPORT QgsLayoutGuideCollection : public QAbstractTableModel, public QgsLayoutSerializableObject
168{
169 Q_OBJECT
170
171 public:
173
174 // *INDENT-OFF*
175
183 {
184 Orientation SIP_MONKEYPATCH_COMPAT_NAME( OrientationRole ) = Qt::UserRole,
185 Position SIP_MONKEYPATCH_COMPAT_NAME( PositionRole ),
186 Units SIP_MONKEYPATCH_COMPAT_NAME( UnitsRole ),
188 LayoutPosition SIP_MONKEYPATCH_COMPAT_NAME( LayoutPositionRole ),
189 };
190 Q_ENUM( CustomRole )
191 // *INDENT-ON*
192
193
198 ~QgsLayoutGuideCollection() override;
199
200 QString stringType() const override { return u"LayoutGuideCollection"_s; }
201 QgsLayout *layout() override;
202
203 int rowCount( const QModelIndex & ) const override;
204 int columnCount( const QModelIndex & ) const override;
205 QVariant data( const QModelIndex &index, int role ) const override;
206 bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
207 Qt::ItemFlags flags( const QModelIndex &index ) const override;
208 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
209 bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
210
216 void addGuide( QgsLayoutGuide *guide SIP_TRANSFER );
217
222 void removeGuide( QgsLayoutGuide *guide );
223
227 void setGuideLayoutPosition( QgsLayoutGuide *guide, double position );
228
233 void clear();
234
238 void applyGuidesToAllOtherPages( int sourcePage );
239
243 void update();
244
248 QList< QgsLayoutGuide * > guides();
249
256 QList< QgsLayoutGuide * > guides( Qt::Orientation orientation, int page = -1 );
257
262 QList< QgsLayoutGuide * > guidesOnPage( int page );
263
268 bool visible() const;
269
274 void setVisible( bool visible );
275
280 bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
281
286 bool readXml( const QDomElement &collectionElement, const QDomDocument &document, const QgsReadWriteContext &context ) override;
287
288 private slots:
289
290 void pageAboutToBeRemoved( int pageNumber );
291
292 private:
293 enum UndoRoles
294 {
295 Move = 10000,
296 Remove = 20000,
297 };
298
299 QgsLayout *mLayout = nullptr;
300 QgsLayoutPageCollection *mPageCollection = nullptr;
301
302 QList< QgsLayoutGuide * > mGuides;
303 int mHeaderSize = 0;
304
305 bool mGuidesVisible = true;
306 bool mBlockUndoCommands = false;
307
309};
310
311
317class CORE_EXPORT QgsLayoutGuideProxyModel : public QSortFilterProxyModel
318{
319 Q_OBJECT
320
321 public:
327 explicit QgsLayoutGuideProxyModel( QObject *parent SIP_TRANSFERTHIS, Qt::Orientation orientation, int page );
328
332 void setPage( int page );
333
334 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
335 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
336
337 private:
338 Qt::Orientation mOrientation = Qt::Horizontal;
339 int mPage = 0;
340};
341
342#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:52
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:267
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:269