QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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"
20 #include "qgslayoutmeasurement.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 
30 class QgsLayout;
32 class QDomElement;
33 class QDomDocument;
35 
42 class CORE_EXPORT QgsLayoutGuide : public QObject
43 {
44 
45  Q_OBJECT
46 
47  public:
48 
57  QgsLayoutGuide( Qt::Orientation orientation, QgsLayoutMeasurement position, QgsLayoutItemPage *page );
58 
59  ~QgsLayoutGuide() override;
60 
65  QgsLayout *layout() const;
66 
75  void setLayout( QgsLayout *layout );
76 
80  Qt::Orientation orientation() const;
81 
90  QgsLayoutMeasurement position() const;
91 
100  void setPosition( QgsLayoutMeasurement position );
101 
107  QgsLayoutItemPage *page();
108 
114  void setPage( QgsLayoutItemPage *page );
115 
119  void update();
120 
124  QGraphicsLineItem *item();
125 
130  double layoutPosition() const;
131 
136  void setLayoutPosition( double position );
137 
138  signals:
139 
144 
145  private:
146 
147  Qt::Orientation mOrientation = Qt::Vertical;
148 
150  QgsLayoutMeasurement mPosition;
151 
153  QPointer< QgsLayoutItemPage > mPage;
154 
155  QPointer< QgsLayout > mLayout;
156 
158  QGraphicsLineItem *mLineItem = nullptr;
159 
160 };
161 
168 class CORE_EXPORT QgsLayoutGuideCollection : public QAbstractTableModel, public QgsLayoutSerializableObject
169 {
170 
171  Q_OBJECT
172 
173  public:
174 
176  enum Roles
177  {
178  OrientationRole = Qt::UserRole,
183  };
184 
189  QgsLayoutGuideCollection( QgsLayout *layout, QgsLayoutPageCollection *pageCollection );
190  ~QgsLayoutGuideCollection() override;
191 
192  QString stringType() const override { return QStringLiteral( "LayoutGuideCollection" ); }
193  QgsLayout *layout() override;
194 
195  int rowCount( const QModelIndex & ) const override;
196  int columnCount( const QModelIndex & ) const override;
197  QVariant data( const QModelIndex &index, int role ) const override;
198  bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
199  Qt::ItemFlags flags( const QModelIndex &index ) const override;
200  QVariant headerData( int section, Qt::Orientation orientation,
201  int role = Qt::DisplayRole ) const override;
202  bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
203 
209  void addGuide( QgsLayoutGuide *guide SIP_TRANSFER );
210 
215  void removeGuide( QgsLayoutGuide *guide );
216 
220  void setGuideLayoutPosition( QgsLayoutGuide *guide, double position );
221 
226  void clear();
227 
231  void applyGuidesToAllOtherPages( int sourcePage );
232 
236  void update();
237 
241  QList< QgsLayoutGuide * > guides();
242 
249  QList< QgsLayoutGuide * > guides( Qt::Orientation orientation, int page = -1 );
250 
255  QList< QgsLayoutGuide * > guidesOnPage( int page );
256 
261  bool visible() const;
262 
267  void setVisible( bool visible );
268 
273  bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
274 
279  bool readXml( const QDomElement &collectionElement, const QDomDocument &document, const QgsReadWriteContext &context ) override;
280 
281  private slots:
282 
283  void pageAboutToBeRemoved( int pageNumber );
284 
285  private:
286 
287  enum UndoRoles
288  {
289  Move = 10000,
290  Remove = 20000,
291  };
292 
293  QgsLayout *mLayout = nullptr;
294  QgsLayoutPageCollection *mPageCollection = nullptr;
295 
296  QList< QgsLayoutGuide * > mGuides;
297  int mHeaderSize = 0;
298 
299  bool mGuidesVisible = true;
300  bool mBlockUndoCommands = false;
301 
302  friend class QgsLayoutGuideCollectionUndoCommand;
303 
304 };
305 
306 
313 class CORE_EXPORT QgsLayoutGuideProxyModel : public QSortFilterProxyModel
314 {
315  Q_OBJECT
316 
317  public:
318 
324  explicit QgsLayoutGuideProxyModel( QObject *parent SIP_TRANSFERTHIS, Qt::Orientation orientation, int page );
325 
329  void setPage( int page );
330 
331  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
332  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
333 
334  private:
335  Qt::Orientation mOrientation = Qt::Horizontal;
336  int mPage = 0;
337 
338 };
339 
340 #endif //QGSLAYOUTGUIDECOLLECTION_H
Stores and manages the snap guides used by a layout.
QString stringType() const override
Returns the object type as a string.
@ PositionRole
Guide position role.
@ LayoutPositionRole
Guide position in layout coordinates.
@ UnitsRole
Guide position units role.
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:51
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_TRANSFER
Definition: qgis_sip.h:36