QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 public:
46
47 QString stringType() const override { return u"LayoutSnapper"_s; }
48 QgsLayout *layout() override;
49
54 void setSnapTolerance( int snapTolerance );
55
60 int snapTolerance() const { return mTolerance; }
61
66 bool snapToGrid() const { return mSnapToGrid; }
67
72 void setSnapToGrid( bool enabled );
73
78 bool snapToGuides() const { return mSnapToGuides; }
79
84 void setSnapToGuides( bool enabled );
85
90 bool snapToItems() const { return mSnapToItems; }
91
96 void setSnapToItems( bool enabled );
97
114 QPointF snapPoint(
115 QPointF point, double scaleFactor, bool &snapped SIP_OUT, QGraphicsLineItem *horizontalSnapLine = nullptr, QGraphicsLineItem *verticalSnapLine = nullptr, const QList< QgsLayoutItem * > *ignoreItems = nullptr
116 ) const;
117
137 QRectF snapRect(
138 const QRectF &rect,
139 double scaleFactor,
140 bool &snapped SIP_OUT,
141 QGraphicsLineItem *horizontalSnapLine = nullptr,
142 QGraphicsLineItem *verticalSnapLine = nullptr,
143 const QList< QgsLayoutItem * > *ignoreItems = nullptr
144 ) const;
145
160 QPointF snapPointToGrid( QPointF point, double scaleFactor, bool &snappedX SIP_OUT, bool &snappedY SIP_OUT ) const;
161
177 QPointF snapPointsToGrid( const QList< QPointF > &points, double scaleFactor, bool &snappedX SIP_OUT, bool &snappedY SIP_OUT ) const;
178
192 double snapPointToGuides( double original, Qt::Orientation orientation, double scaleFactor, bool &snapped SIP_OUT ) const;
193
209 double snapPointsToGuides( const QList< double > &points, Qt::Orientation orientation, double scaleFactor, bool &snapped SIP_OUT ) const;
210
229 double snapPointToItems( double original, Qt::Orientation orientation, double scaleFactor, const QList< QgsLayoutItem * > &ignoreItems, bool &snapped SIP_OUT, QGraphicsLineItem *snapLine = nullptr ) const;
230
246 double snapPointsToItems(
247 const QList< double > &points, Qt::Orientation orientation, double scaleFactor, const QList< QgsLayoutItem * > &ignoreItems, bool &snapped SIP_OUT, QGraphicsLineItem *snapLine = nullptr
248 ) const;
249
254 bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
255
260 bool readXml( const QDomElement &gridElement, const QDomDocument &document, const QgsReadWriteContext &context ) override;
261
262 private:
263 // Used for 'collapsing' undo commands
264 enum UndoCommand
265 {
266 UndoTolerance = 1,
267 UndoSnapToGrid,
268 UndoSnapToGuides,
269 };
270
271 QgsLayout *mLayout = nullptr;
272
273 int mTolerance = 5;
274 bool mSnapToGrid = false;
275 bool mSnapToGuides = true;
276 bool mSnapToItems = true;
277
279};
280
281#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:57