QGIS API Documentation 3.99.0-Master (e9821da5c6b)
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"
22#include "qgslayoutpoint.h"
24
25#include <QPen>
26#include <QString>
27
28using namespace Qt::StringLiterals;
29
30class QgsLayout;
32
40{
41
42 public:
43
48
49 QString stringType() const override { return u"LayoutSnapper"_s; }
50 QgsLayout *layout() override;
51
56 void setSnapTolerance( int snapTolerance );
57
62 int snapTolerance() const { return mTolerance; }
63
68 bool snapToGrid() const { return mSnapToGrid; }
69
74 void setSnapToGrid( bool enabled );
75
80 bool snapToGuides() const { return mSnapToGuides; }
81
86 void setSnapToGuides( bool enabled );
87
92 bool snapToItems() const { return mSnapToItems; }
93
98 void setSnapToItems( bool enabled );
99
116 QPointF snapPoint( QPointF point, double scaleFactor, bool &snapped SIP_OUT, QGraphicsLineItem *horizontalSnapLine = nullptr,
117 QGraphicsLineItem *verticalSnapLine = nullptr,
118 const QList< QgsLayoutItem * > *ignoreItems = nullptr ) const;
119
139 QRectF snapRect( const QRectF &rect, double scaleFactor, bool &snapped SIP_OUT, QGraphicsLineItem *horizontalSnapLine = nullptr,
140 QGraphicsLineItem *verticalSnapLine = nullptr,
141 const QList< QgsLayoutItem * > *ignoreItems = nullptr ) const;
142
157 QPointF snapPointToGrid( QPointF point, double scaleFactor, bool &snappedX SIP_OUT, bool &snappedY SIP_OUT ) const;
158
174 QPointF snapPointsToGrid( const QList< QPointF > &points, double scaleFactor, bool &snappedX SIP_OUT, bool &snappedY SIP_OUT ) const;
175
189 double snapPointToGuides( double original, Qt::Orientation orientation, double scaleFactor, bool &snapped SIP_OUT ) const;
190
206 double snapPointsToGuides( const QList< double > &points, Qt::Orientation orientation, double scaleFactor, bool &snapped SIP_OUT ) const;
207
226 double snapPointToItems( double original, Qt::Orientation orientation, double scaleFactor, const QList< QgsLayoutItem * > &ignoreItems, bool &snapped SIP_OUT,
227 QGraphicsLineItem *snapLine = nullptr ) const;
228
244 double snapPointsToItems( const QList< double > &points, Qt::Orientation orientation, double scaleFactor, const QList< QgsLayoutItem * > &ignoreItems, bool &snapped SIP_OUT,
245 QGraphicsLineItem *snapLine = nullptr ) const;
246
251 bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
252
257 bool readXml( const QDomElement &gridElement, const QDomDocument &document, const QgsReadWriteContext &context ) override;
258
259 private:
260
261 // Used for 'collapsing' undo commands
262 enum UndoCommand
263 {
264 UndoTolerance = 1,
265 UndoSnapToGrid,
266 UndoSnapToGuides,
267 };
268
269 QgsLayout *mLayout = nullptr;
270
271 int mTolerance = 5;
272 bool mSnapToGrid = false;
273 bool mSnapToGuides = true;
274 bool mSnapToItems = true;
275
277
278};
279
280#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.
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.
friend class QgsLayoutSnapperUndoCommand
QgsLayoutSnapper(QgsLayout *layout)
Constructor for QgsLayoutSnapper, attached to the specified layout.
QgsLayout * layout() override
Returns the layout the object belongs to.
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:50
A container for the context for various read/write operations on objects.
#define SIP_OUT
Definition qgis_sip.h:58