QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
layout
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
20
#include "
qgis.h
"
21
#include "
qgsunittypes.h
"
22
23
#include <QString>
24
#include <QStringList>
25
26
using namespace
Qt::StringLiterals;
27
28
QgsLayoutPoint::QgsLayoutPoint
(
const
double
x
,
const
double
y
,
const
Qgis::LayoutUnit
units
)
29
: mX(
x
)
30
, mY(
y
)
31
, mUnits(
units
)
32
{
33
#ifdef QGISDEBUG
34
Q_ASSERT_X( !std::isnan( mX ) && !std::isnan( mY ),
"QgsLayoutPoint"
,
"Layout point with NaN coordinates created"
);
35
#endif
36
}
37
38
QgsLayoutPoint::QgsLayoutPoint
(
const
QPointF point,
const
Qgis::LayoutUnit
units
)
39
: mX( point.
x
() )
40
, mY( point.
y
() )
41
, mUnits(
units
)
42
{}
43
44
QgsLayoutPoint::QgsLayoutPoint
(
const
Qgis::LayoutUnit
units
)
45
: mUnits(
units
)
46
{}
47
48
bool
QgsLayoutPoint::isNull
()
const
49
{
50
return
qgsDoubleNear
( mX, 0 ) &&
qgsDoubleNear
( mY, 0 );
51
}
52
53
QPointF
QgsLayoutPoint::toQPointF
()
const
54
{
55
return
QPointF( mX, mY );
56
}
57
58
QString
QgsLayoutPoint::encodePoint
()
const
59
{
60
return
u
"%1,%2,%3"
_s.arg( mX ).arg( mY ).arg(
QgsUnitTypes::encodeUnit
( mUnits ) );
61
}
62
63
QgsLayoutPoint
QgsLayoutPoint::decodePoint
(
const
QString &
string
)
64
{
65
QStringList parts =
string
.split(
','
);
66
if
( parts.count() != 3 )
67
{
68
return
QgsLayoutPoint
();
69
}
70
const
double
x
= parts[0].toDouble();
71
const
double
y
= parts[1].toDouble();
72
73
// don't restore corrupted coordinates from xml. This can happen when eg a broken item size causes a nan position,
74
// which breaks the layout size calculation and results in nan or massive x/y values. Restoring these leads to a broken
75
// layout which cannot be interacted with.
76
if
( std::isnan(
x
) || std::isnan(
y
) ||
x
> 9.99998e+06 ||
y
> 9.99998e+06 )
77
return
QgsLayoutPoint
();
78
79
return
QgsLayoutPoint
(
x
,
y
,
QgsUnitTypes::decodeLayoutUnit
( parts[2] ) );
80
}
81
82
bool
QgsLayoutPoint::operator==
(
const
QgsLayoutPoint
&other )
const
83
{
84
return
other.
units
() == mUnits &&
qgsDoubleNear
( other.
x
(), mX ) &&
qgsDoubleNear
( other.
y
(), mY );
85
}
86
87
bool
QgsLayoutPoint::operator!=
(
const
QgsLayoutPoint
&other )
const
88
{
89
return
( !
operator
==( other ) );
90
}
91
92
QgsLayoutPoint
QgsLayoutPoint::operator*
(
const
double
v )
const
93
{
94
return
QgsLayoutPoint
( mX * v, mY * v, mUnits );
95
}
96
97
QgsLayoutPoint
QgsLayoutPoint::operator*=
(
const
double
v )
98
{
99
*
this
= *
this
* v;
100
return
*
this
;
101
}
102
103
QgsLayoutPoint
QgsLayoutPoint::operator/
(
const
double
v )
const
104
{
105
return
QgsLayoutPoint
( mX / v, mY / v, mUnits );
106
}
107
108
QgsLayoutPoint
QgsLayoutPoint::operator/=
(
const
double
v )
109
{
110
*
this
= *
this
/ v;
111
return
*
this
;
112
}
Qgis::LayoutUnit
LayoutUnit
Layout measurement units.
Definition
qgis.h:5778
QgsLayoutPoint::operator/=
QgsLayoutPoint operator/=(double v)
Divides the x and y by a scalar value.
Definition
qgslayoutpoint.cpp:108
QgsLayoutPoint::x
double x() const
Returns x coordinate of point.
Definition
qgslayoutpoint.h:82
QgsLayoutPoint::toQPointF
QPointF toQPointF() const
Converts the layout point to a QPointF.
Definition
qgslayoutpoint.cpp:53
QgsLayoutPoint::encodePoint
QString encodePoint() const
Encodes the layout point to a string.
Definition
qgslayoutpoint.cpp:58
QgsLayoutPoint::operator/
QgsLayoutPoint operator/(double v) const
Divides the x and y by a scalar value.
Definition
qgslayoutpoint.cpp:103
QgsLayoutPoint::decodePoint
static QgsLayoutPoint decodePoint(const QString &string)
Decodes a point from a string.
Definition
qgslayoutpoint.cpp:63
QgsLayoutPoint::isNull
bool isNull() const
Tests whether the position is null, ie both its x and y coordinates are zero.
Definition
qgslayoutpoint.cpp:48
QgsLayoutPoint::y
double y() const
Returns y coordinate of point.
Definition
qgslayoutpoint.h:102
QgsLayoutPoint::QgsLayoutPoint
QgsLayoutPoint(double x, double y, Qgis::LayoutUnit units=Qgis::LayoutUnit::Millimeters)
Constructor for QgsLayoutPoint.
Definition
qgslayoutpoint.cpp:28
QgsLayoutPoint::operator*=
QgsLayoutPoint operator*=(double v)
Multiplies the x and y by a scalar value.
Definition
qgslayoutpoint.cpp:97
QgsLayoutPoint::operator==
bool operator==(const QgsLayoutPoint &other) const
Definition
qgslayoutpoint.cpp:82
QgsLayoutPoint::units
Qgis::LayoutUnit units() const
Returns the units for the point.
Definition
qgslayoutpoint.h:121
QgsLayoutPoint::operator!=
bool operator!=(const QgsLayoutPoint &other) const
Definition
qgslayoutpoint.cpp:87
QgsLayoutPoint::operator*
QgsLayoutPoint operator*(double v) const
Multiplies the x and y by a scalar value.
Definition
qgslayoutpoint.cpp:92
QgsUnitTypes::decodeLayoutUnit
static Q_INVOKABLE Qgis::LayoutUnit decodeLayoutUnit(const QString &string, bool *ok=nullptr)
Decodes a layout unit from a string.
Definition
qgsunittypes.cpp:3519
QgsUnitTypes::encodeUnit
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
Definition
qgsunittypes.cpp:169
qgis.h
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:7743
qgslayoutpoint.h
qgsunittypes.h
Generated on
for QGIS API Documentation by
1.17.0