QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
21 #include <QStringList>
22 
23 QgsLayoutPoint::QgsLayoutPoint( const double x, const double y, const QgsUnitTypes::LayoutUnit units )
24  : mX( x )
25  , mY( y )
26  , mUnits( units )
27 {
28 
29 }
30 
31 QgsLayoutPoint::QgsLayoutPoint( const QPointF point, const QgsUnitTypes::LayoutUnit units )
32  : mX( point.x() )
33  , mY( point.y() )
34  , mUnits( units )
35 {
36 
37 }
38 
40  : mUnits( units )
41 {
42 
43 }
44 
46 {
47  return qgsDoubleNear( mX, 0 ) && qgsDoubleNear( mY, 0 );
48 }
49 
51 {
52  return QPointF( mX, mY );
53 }
54 
56 {
57  return QStringLiteral( "%1,%2,%3" ).arg( mX ).arg( mY ).arg( QgsUnitTypes::encodeUnit( mUnits ) );
58 }
59 
61 {
62  QStringList parts = string.split( ',' );
63  if ( parts.count() != 3 )
64  {
65  return QgsLayoutPoint();
66  }
67  return QgsLayoutPoint( parts[0].toDouble(), parts[1].toDouble(), QgsUnitTypes::decodeLayoutUnit( parts[2] ) );
68 }
69 
70 bool QgsLayoutPoint::operator==( const QgsLayoutPoint &other ) const
71 {
72  return other.units() == mUnits && qgsDoubleNear( other.x(), mX ) && qgsDoubleNear( other.y(), mY );
73 }
74 
75 bool QgsLayoutPoint::operator!=( const QgsLayoutPoint &other ) const
76 {
77  return ( ! operator==( other ) );
78 }
79 
81 {
82  return QgsLayoutPoint( mX * v, mY * v, mUnits );
83 }
84 
86 {
87  *this = *this * v;
88  return *this;
89 }
90 
92 {
93  return QgsLayoutPoint( mX / v, mY / v, mUnits );
94 }
95 
97 {
98  *this = *this / v;
99  return *this;
100 }
QgsLayoutPoint::operator*
QgsLayoutPoint operator*(double v) const
Multiplies the x and y by a scalar value.
Definition: qgslayoutpoint.cpp:80
QgsLayoutPoint::operator/
QgsLayoutPoint operator/(double v) const
Divides the x and y by a scalar value.
Definition: qgslayoutpoint.cpp:91
QgsUnitTypes::LayoutUnit
LayoutUnit
Layout measurement units.
Definition: qgsunittypes.h:181
QgsLayoutPoint::QgsLayoutPoint
QgsLayoutPoint(double x, double y, QgsUnitTypes::LayoutUnit units=QgsUnitTypes::LayoutMillimeters)
Constructor for QgsLayoutPoint.
Definition: qgslayoutpoint.cpp:23
QgsLayoutPoint::y
double y() const
Returns y coordinate of point.
Definition: qgslayoutpoint.h:86
qgis.h
QgsLayoutPoint::isNull
bool isNull() const
Tests whether the position is null, ie both its x and y coordinates are zero.
Definition: qgslayoutpoint.cpp:45
QgsLayoutPoint::operator==
bool operator==(const QgsLayoutPoint &other) const
Definition: qgslayoutpoint.cpp:70
qgslayoutpoint.h
QgsUnitTypes::encodeUnit
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
Definition: qgsunittypes.cpp:122
qgsDoubleNear
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:315
QgsLayoutPoint::operator!=
bool operator!=(const QgsLayoutPoint &other) const
Definition: qgslayoutpoint.cpp:75
QgsLayoutPoint::operator/=
QgsLayoutPoint operator/=(double v)
Divides the x and y by a scalar value.
Definition: qgslayoutpoint.cpp:96
QgsLayoutPoint::operator*=
QgsLayoutPoint operator*=(double v)
Multiplies the x and y by a scalar value.
Definition: qgslayoutpoint.cpp:85
QgsLayoutPoint::toQPointF
QPointF toQPointF() const
Converts the layout point to a QPointF.
Definition: qgslayoutpoint.cpp:50
QgsLayoutPoint::decodePoint
static QgsLayoutPoint decodePoint(const QString &string)
Decodes a point from a string.
Definition: qgslayoutpoint.cpp:60
QgsLayoutPoint
This class provides a method of storing points, consisting of an x and y coordinate,...
Definition: qgslayoutpoint.h:40
QgsUnitTypes::decodeLayoutUnit
static Q_INVOKABLE QgsUnitTypes::LayoutUnit decodeLayoutUnit(const QString &string, bool *ok=nullptr)
Decodes a layout unit from a string.
Definition: qgsunittypes.cpp:2995
QgsLayoutPoint::x
double x() const
Returns x coordinate of point.
Definition: qgslayoutpoint.h:72
QgsLayoutPoint::encodePoint
QString encodePoint() const
Encodes the layout point to a string.
Definition: qgslayoutpoint.cpp:55
QgsLayoutPoint::units
QgsUnitTypes::LayoutUnit units() const
Returns the units for the point.
Definition: qgslayoutpoint.h:99