QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
layout
qgslayoutmeasurement.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgslayoutmeasurement.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 "
qgslayoutmeasurement.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
QgsLayoutMeasurement::QgsLayoutMeasurement
(
const
double
length
,
const
Qgis::LayoutUnit
units
)
29
: mLength(
length
)
30
, mUnits(
units
)
31
{}
32
33
QString
QgsLayoutMeasurement::encodeMeasurement
()
const
34
{
35
return
u
"%1,%2"
_s.arg( mLength ).arg(
QgsUnitTypes::encodeUnit
( mUnits ) );
36
}
37
38
QgsLayoutMeasurement
QgsLayoutMeasurement::decodeMeasurement
(
const
QString &
string
)
39
{
40
QStringList parts =
string
.split(
','
);
41
if
( parts.count() != 2 )
42
{
43
return
QgsLayoutMeasurement
( 0 );
44
}
45
return
QgsLayoutMeasurement
( parts[0].toDouble(),
QgsUnitTypes::decodeLayoutUnit
( parts[1] ) );
46
}
47
48
bool
QgsLayoutMeasurement::operator==
(
const
QgsLayoutMeasurement
other )
const
49
{
50
return
other.
units
() == mUnits &&
qgsDoubleNear
( other.
length
(), mLength );
51
}
52
53
bool
QgsLayoutMeasurement::operator!=
(
const
QgsLayoutMeasurement
other )
const
54
{
55
return
( !
operator
==( other ) );
56
}
57
58
QgsLayoutMeasurement
QgsLayoutMeasurement::operator+
(
const
double
v )
const
59
{
60
return
QgsLayoutMeasurement
( mLength + v, mUnits );
61
}
62
63
QgsLayoutMeasurement
QgsLayoutMeasurement::operator+=
(
const
double
v )
64
{
65
*
this
= *
this
+ v;
66
return
*
this
;
67
}
68
69
QgsLayoutMeasurement
QgsLayoutMeasurement::operator-
(
const
double
v )
const
70
{
71
return
QgsLayoutMeasurement
( mLength - v, mUnits );
72
}
73
74
QgsLayoutMeasurement
QgsLayoutMeasurement::operator-=
(
const
double
v )
75
{
76
*
this
= *
this
- v;
77
return
*
this
;
78
}
79
80
QgsLayoutMeasurement
QgsLayoutMeasurement::operator*
(
const
double
v )
const
81
{
82
return
QgsLayoutMeasurement
( mLength * v, mUnits );
83
}
84
85
QgsLayoutMeasurement
QgsLayoutMeasurement::operator*=
(
const
double
v )
86
{
87
*
this
= *
this
* v;
88
return
*
this
;
89
}
90
91
QgsLayoutMeasurement
QgsLayoutMeasurement::operator/
(
const
double
v )
const
92
{
93
return
QgsLayoutMeasurement
( mLength / v, mUnits );
94
}
95
96
QgsLayoutMeasurement
QgsLayoutMeasurement::operator/=
(
const
double
v )
97
{
98
*
this
= *
this
/ v;
99
return
*
this
;
100
}
Qgis::LayoutUnit
LayoutUnit
Layout measurement units.
Definition
qgis.h:5778
QgsLayoutMeasurement::decodeMeasurement
static QgsLayoutMeasurement decodeMeasurement(const QString &string)
Decodes a measurement from a string.
Definition
qgslayoutmeasurement.cpp:38
QgsLayoutMeasurement::encodeMeasurement
QString encodeMeasurement() const
Encodes the layout measurement to a string.
Definition
qgslayoutmeasurement.cpp:33
QgsLayoutMeasurement::operator/=
QgsLayoutMeasurement operator/=(double v)
Divides the measurement by a scalar value.
Definition
qgslayoutmeasurement.cpp:96
QgsLayoutMeasurement::operator*=
QgsLayoutMeasurement operator*=(double v)
Multiplies the measurement by a scalar value.
Definition
qgslayoutmeasurement.cpp:85
QgsLayoutMeasurement::units
Qgis::LayoutUnit units() const
Returns the units for the measurement.
Definition
qgslayoutmeasurement.h:62
QgsLayoutMeasurement::operator-
QgsLayoutMeasurement operator-(double v) const
Subtracts a scalar value from the measurement.
Definition
qgslayoutmeasurement.cpp:69
QgsLayoutMeasurement::operator+=
QgsLayoutMeasurement operator+=(double v)
Adds a scalar value to the measurement.
Definition
qgslayoutmeasurement.cpp:63
QgsLayoutMeasurement::operator==
bool operator==(QgsLayoutMeasurement other) const
Definition
qgslayoutmeasurement.cpp:48
QgsLayoutMeasurement::operator+
QgsLayoutMeasurement operator+(double v) const
Adds a scalar value to the measurement.
Definition
qgslayoutmeasurement.cpp:58
QgsLayoutMeasurement::QgsLayoutMeasurement
QgsLayoutMeasurement(double length, Qgis::LayoutUnit units=Qgis::LayoutUnit::Millimeters)
Constructor for QgsLayoutMeasurement.
Definition
qgslayoutmeasurement.cpp:28
QgsLayoutMeasurement::operator-=
QgsLayoutMeasurement operator-=(double v)
Subtracts a scalar value from the measurement.
Definition
qgslayoutmeasurement.cpp:74
QgsLayoutMeasurement::length
double length() const
Returns the length of the measurement.
Definition
qgslayoutmeasurement.h:50
QgsLayoutMeasurement::operator!=
bool operator!=(QgsLayoutMeasurement other) const
Definition
qgslayoutmeasurement.cpp:53
QgsLayoutMeasurement::operator*
QgsLayoutMeasurement operator*(double v) const
Multiplies the measurement by a scalar value.
Definition
qgslayoutmeasurement.cpp:80
QgsLayoutMeasurement::operator/
QgsLayoutMeasurement operator/(double v) const
Divides the measurement by a scalar value.
Definition
qgslayoutmeasurement.cpp:91
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
qgslayoutmeasurement.h
qgsunittypes.h
Generated on
for QGIS API Documentation by
1.17.0