QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
qgslayoutsnapper.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutsnapper.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 QGSLAYOUTSNAPPER_H
17#define QGSLAYOUTSNAPPER_H
18
19#include "qgis_core.h"
21#include "qgslayoutpoint.h"
24#include <QPen>
25
26class QgsLayout;
28
36{
37
38 public:
39
43 QgsLayoutSnapper( QgsLayout *layout );
44
45 QString stringType() const override { return QStringLiteral( "LayoutSnapper" ); }
46 QgsLayout *layout() override;
47
52 void setSnapTolerance( int snapTolerance );
53
58 int snapTolerance() const { return mTolerance; }
59
64 bool snapToGrid() const { return mSnapToGrid; }
65
70 void setSnapToGrid( bool enabled );
71
76 bool snapToGuides() const { return mSnapToGuides; }
77
82 void setSnapToGuides( bool enabled );
83
88 bool snapToItems() const { return mSnapToItems; }
89
94 void setSnapToItems( bool enabled );
95
112 QPointF snapPoint( QPointF point, double scaleFactor, bool &snapped SIP_OUT, QGraphicsLineItem *horizontalSnapLine = nullptr,
113 QGraphicsLineItem *verticalSnapLine = nullptr,
114 const QList< QgsLayoutItem * > *ignoreItems = nullptr ) const;
115
135 QRectF snapRect( const QRectF &rect, double scaleFactor, bool &snapped SIP_OUT, QGraphicsLineItem *horizontalSnapLine = nullptr,
136 QGraphicsLineItem *verticalSnapLine = nullptr,
137 const QList< QgsLayoutItem * > *ignoreItems = nullptr ) const;
138
153 QPointF snapPointToGrid( QPointF point, double scaleFactor, bool &snappedX SIP_OUT, bool &snappedY SIP_OUT ) const;
154
170 QPointF snapPointsToGrid( const QList< QPointF > &points, double scaleFactor, bool &snappedX SIP_OUT, bool &snappedY SIP_OUT ) const;
171
185 double snapPointToGuides( double original, Qt::Orientation orientation, double scaleFactor, bool &snapped SIP_OUT ) const;
186
202 double snapPointsToGuides( const QList< double > &points, Qt::Orientation orientation, double scaleFactor, bool &snapped SIP_OUT ) const;
203
222 double snapPointToItems( double original, Qt::Orientation orientation, double scaleFactor, const QList< QgsLayoutItem * > &ignoreItems, bool &snapped SIP_OUT,
223 QGraphicsLineItem *snapLine = nullptr ) const;
224
240 double snapPointsToItems( const QList< double > &points, Qt::Orientation orientation, double scaleFactor, const QList< QgsLayoutItem * > &ignoreItems, bool &snapped SIP_OUT,
241 QGraphicsLineItem *snapLine = nullptr ) const;
242
247 bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
248
253 bool readXml( const QDomElement &gridElement, const QDomDocument &document, const QgsReadWriteContext &context ) override;
254
255 private:
256
257 // Used for 'collapsing' undo commands
258 enum UndoCommand
259 {
260 UndoTolerance = 1,
261 UndoSnapToGrid,
262 UndoSnapToGuides,
263 };
264
265 QgsLayout *mLayout = nullptr;
266
267 int mTolerance = 5;
268 bool mSnapToGrid = false;
269 bool mSnapToGuides = true;
270 bool mSnapToItems = true;
271
272 friend class QgsLayoutSnapperUndoCommand;
273
274};
275
276#endif //QGSLAYOUTSNAPPER_H
An interface for layout objects which can be stored and read from DOM elements.
virtual bool writeXml(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const =0
Stores the objects's state in a DOM element.
virtual bool readXml(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)=0
Sets the objects's state from a DOM element.
virtual QgsLayout * layout()=0
Returns the layout the object belongs to.
Manages snapping grids and preset snap lines in a layout, and handles snapping points to the nearest ...
QString stringType() const override
Returns the object type as a string.
bool snapToItems() const
Returns true if snapping to items is enabled.
int snapTolerance() const
Returns the snap tolerance (in pixels) to use when snapping.
bool snapToGrid() const
Returns true if snapping to grid is enabled.
bool snapToGuides() const
Returns true if snapping to guides is enabled.
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_OUT
Definition qgis_sip.h:58