QGIS API Documentation 3.99.0-Master (d270888f95f)
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 <QString>
24#include <QStringList>
25
26using namespace Qt::StringLiterals;
27
29 : mLength( length )
30 , mUnits( units )
31{
32}
33
35{
36 return u"%1,%2"_s.arg( mLength ).arg( QgsUnitTypes::encodeUnit( mUnits ) );
37}
38
40{
41 QStringList parts = string.split( ',' );
42 if ( parts.count() != 2 )
43 {
44 return QgsLayoutMeasurement( 0 );
45 }
46 return QgsLayoutMeasurement( parts[0].toDouble(), QgsUnitTypes::decodeLayoutUnit( parts[1] ) );
47}
48
50{
51 return other.units() == mUnits && qgsDoubleNear( other.length(), mLength );
52}
53
55{
56 return ( ! operator==( other ) );
57}
58
60{
61 return QgsLayoutMeasurement( mLength + v, mUnits );
62}
63
65{
66 *this = *this + v;
67 return *this;
68}
69
71{
72 return QgsLayoutMeasurement( mLength - v, mUnits );
73}
74
76{
77 *this = *this - v;
78 return *this;
79}
80
82{
83 return QgsLayoutMeasurement( mLength * v, mUnits );
84}
85
87{
88 *this = *this * v;
89 return *this;
90}
91
93{
94 return QgsLayoutMeasurement( mLength / v, mUnits );
95}
96
98{
99 *this = *this / v;
100 return *this;
101}
LayoutUnit
Layout measurement units.
Definition qgis.h:5275
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:6900