QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgslayoutpoint.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutpoint.cpp
3 ------------------
4 begin : June 2017
5 copyright : (C) 2017 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#include "qgslayoutpoint.h"
19#include "qgis.h"
20#include "qgsunittypes.h"
21
22#include <QStringList>
23
24QgsLayoutPoint::QgsLayoutPoint( const double x, const double y, const Qgis::LayoutUnit units )
25 : mX( x )
26 , mY( y )
27 , mUnits( units )
28{
29
30}
31
32QgsLayoutPoint::QgsLayoutPoint( const QPointF point, const Qgis::LayoutUnit units )
33 : mX( point.x() )
34 , mY( point.y() )
35 , mUnits( units )
36{
37
38}
39
41 : mUnits( units )
42{
43
44}
45
47{
48 return qgsDoubleNear( mX, 0 ) && qgsDoubleNear( mY, 0 );
49}
50
52{
53 return QPointF( mX, mY );
54}
55
57{
58 return QStringLiteral( "%1,%2,%3" ).arg( mX ).arg( mY ).arg( QgsUnitTypes::encodeUnit( mUnits ) );
59}
60
62{
63 QStringList parts = string.split( ',' );
64 if ( parts.count() != 3 )
65 {
66 return QgsLayoutPoint();
67 }
68 return QgsLayoutPoint( parts[0].toDouble(), parts[1].toDouble(), QgsUnitTypes::decodeLayoutUnit( parts[2] ) );
69}
70
72{
73 return other.units() == mUnits && qgsDoubleNear( other.x(), mX ) && qgsDoubleNear( other.y(), mY );
74}
75
77{
78 return ( ! operator==( other ) );
79}
80
82{
83 return QgsLayoutPoint( mX * v, mY * v, mUnits );
84}
85
87{
88 *this = *this * v;
89 return *this;
90}
91
93{
94 return QgsLayoutPoint( mX / v, mY / v, mUnits );
95}
96
98{
99 *this = *this / v;
100 return *this;
101}
LayoutUnit
Layout measurement units.
Definition: qgis.h:4275
This class provides a method of storing points, consisting of an x and y coordinate,...
QgsLayoutPoint operator/=(double v)
Divides the x and y by a scalar value.
double x() const
Returns x coordinate of point.
QPointF toQPointF() const
Converts the layout point to a QPointF.
QString encodePoint() const
Encodes the layout point to a string.
QgsLayoutPoint operator/(double v) const
Divides the x and y by a scalar value.
static QgsLayoutPoint decodePoint(const QString &string)
Decodes a point from a string.
bool isNull() const
Tests whether the position is null, ie both its x and y coordinates are zero.
double y() const
Returns y coordinate of point.
QgsLayoutPoint(double x, double y, Qgis::LayoutUnit units=Qgis::LayoutUnit::Millimeters)
Constructor for QgsLayoutPoint.
QgsLayoutPoint operator*=(double v)
Multiplies the x and y by a scalar value.
bool operator==(const QgsLayoutPoint &other) const
Qgis::LayoutUnit units() const
Returns the units for the point.
bool operator!=(const QgsLayoutPoint &other) const
QgsLayoutPoint operator*(double v) const
Multiplies the x and y by a scalar value.
static Q_INVOKABLE Qgis::LayoutUnit decodeLayoutUnit(const QString &string, bool *ok=nullptr)
Decodes a layout unit from a string.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:5207