QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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
19
20#include "qgis.h"
21#include "qgsunittypes.h"
22
23#include <QStringList>
24
26 : mLength( length )
27 , mUnits( units )
28{
29}
30
32{
33 return QStringLiteral( "%1,%2" ).arg( mLength ).arg( QgsUnitTypes::encodeUnit( mUnits ) );
34}
35
37{
38 QStringList parts = string.split( ',' );
39 if ( parts.count() != 2 )
40 {
41 return QgsLayoutMeasurement( 0 );
42 }
43 return QgsLayoutMeasurement( parts[0].toDouble(), QgsUnitTypes::decodeLayoutUnit( parts[1] ) );
44}
45
47{
48 return other.units() == mUnits && qgsDoubleNear( other.length(), mLength );
49}
50
52{
53 return ( ! operator==( other ) );
54}
55
57{
58 return QgsLayoutMeasurement( mLength + v, mUnits );
59}
60
62{
63 *this = *this + v;
64 return *this;
65}
66
68{
69 return QgsLayoutMeasurement( mLength - v, mUnits );
70}
71
73{
74 *this = *this - v;
75 return *this;
76}
77
79{
80 return QgsLayoutMeasurement( mLength * v, mUnits );
81}
82
84{
85 *this = *this * v;
86 return *this;
87}
88
90{
91 return QgsLayoutMeasurement( mLength / v, mUnits );
92}
93
95{
96 *this = *this / v;
97 return *this;
98}
LayoutUnit
Layout measurement units.
Definition qgis.h:5203
static QgsLayoutMeasurement decodeMeasurement(const QString &string)
Decodes a measurement from a string.
QString encodeMeasurement() const
Encodes the layout measurement to a string.
QgsLayoutMeasurement operator/=(double v)
Divides the measurement by a scalar value.
QgsLayoutMeasurement operator*=(double v)
Multiplies the measurement by a scalar value.
Qgis::LayoutUnit units() const
Returns the units for the measurement.
QgsLayoutMeasurement operator-(double v) const
Subtracts a scalar value from the measurement.
QgsLayoutMeasurement operator+=(double v)
Adds a scalar value to the measurement.
bool operator==(QgsLayoutMeasurement other) const
QgsLayoutMeasurement operator+(double v) const
Adds a scalar value to the measurement.
QgsLayoutMeasurement(double length, Qgis::LayoutUnit units=Qgis::LayoutUnit::Millimeters)
Constructor for QgsLayoutMeasurement.
QgsLayoutMeasurement operator-=(double v)
Subtracts a scalar value from the measurement.
double length() const
Returns the length of the measurement.
bool operator!=(QgsLayoutMeasurement other) const
QgsLayoutMeasurement operator*(double v) const
Multiplies the measurement by a scalar value.
QgsLayoutMeasurement operator/(double v) const
Divides the measurement 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:6607