QGIS API Documentation 4.1.0-Master (01362494303)
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;
33
41{
42 public:
47
48 QString stringType() const override { return u"LayoutSnapper"_s; }
49 QgsLayout *layout() override;
50
55 void setSnapTolerance( int snapTolerance );
56
61 int snapTolerance() const { return mTolerance; }
62
67 bool snapToGrid() const { return mSnapToGrid; }
68
73 void setSnapToGrid( bool enabled );
74
79 bool snapToGuides() const { return mSnapToGuides; }
80
85 void setSnapToGuides( bool enabled );
86
91 bool snapToItems() const { return mSnapToItems; }
92
97 void setSnapToItems( bool enabled );
98
115 QPointF snapPoint(
116 QPointF point, double scaleFactor, bool &snapped SIP_OUT, QGraphicsLineItem *horizontalSnapLine = nullptr, QGraphicsLineItem *verticalSnapLine = nullptr, const QList< QgsLayoutItem * > *ignoreItems = nullptr
117 ) const;
118
138 QRectF snapRect(
139 const QRectF &rect,
140 double scaleFactor,
141 bool &snapped SIP_OUT,
142 QGraphicsLineItem *horizontalSnapLine = nullptr,
143 QGraphicsLineItem *verticalSnapLine = nullptr,
144 const QList< QgsLayoutItem * > *ignoreItems = nullptr
145 ) const;
146
161 QPointF snapPointToGrid( QPointF point, double scaleFactor, bool &snappedX SIP_OUT, bool &snappedY SIP_OUT ) const;
162
178 QPointF snapPointsToGrid( const QList< QPointF > &points, double scaleFactor, bool &snappedX SIP_OUT, bool &snappedY SIP_OUT ) const;
179
193 double snapPointToGuides( double original, Qt::Orientation orientation, double scaleFactor, bool &snapped SIP_OUT ) const;
194
210 double snapPointsToGuides( const QList< double > &points, Qt::Orientation orientation, double scaleFactor, bool &snapped SIP_OUT ) const;
211
230 double snapPointToItems( double original, Qt::Orientation orientation, double scaleFactor, const QList< QgsLayoutItem * > &ignoreItems, bool &snapped SIP_OUT, QGraphicsLineItem *snapLine = nullptr ) const;
231
247 double snapPointsToItems(
248 const QList< double > &points, Qt::Orientation orientation, double scaleFactor, const QList< QgsLayoutItem * > &ignoreItems, bool &snapped SIP_OUT, QGraphicsLineItem *snapLine = nullptr
249 ) const;
250
255 bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
256
261 bool readXml( const QDomElement &gridElement, const QDomDocument &document, const QgsReadWriteContext &context ) override;
262
263 private:
264 // Used for 'collapsing' undo commands
265 enum UndoCommand
266 {
267 UndoTolerance = 1,
268 UndoSnapToGrid,
269 UndoSnapToGuides,
270 };
271
272 QgsLayout *mLayout = nullptr;
273
274 int mTolerance = 5;
275 bool mSnapToGrid = false;
276 bool mSnapToGuides = true;
277 bool mSnapToItems = true;
278
280
281 public:
282#ifndef SIP_RUN
284#endif
285};
286
287#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.
static const QgsSettingsEntryInteger * settingsSnapTolerance
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:51
A container for the context for various read/write operations on objects.
An integer settings entry.
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_OUT
Definition qgis_sip.h:57