QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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
34{
35 return u"%1,%2"_s.arg( mLength ).arg( QgsUnitTypes::encodeUnit( mUnits ) );
36}
37
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
49{
50 return other.units() == mUnits && qgsDoubleNear( other.length(), mLength );
51}
52
54{
55 return ( !operator==( other ) );
56}
57
59{
60 return QgsLayoutMeasurement( mLength + v, mUnits );
61}
62
64{
65 *this = *this + v;
66 return *this;
67}
68
70{
71 return QgsLayoutMeasurement( mLength - v, mUnits );
72}
73
75{
76 *this = *this - v;
77 return *this;
78}
79
81{
82 return QgsLayoutMeasurement( mLength * v, mUnits );
83}
84
86{
87 *this = *this * v;
88 return *this;
89}
90
92{
93 return QgsLayoutMeasurement( mLength / v, mUnits );
94}
95
97{
98 *this = *this / v;
99 return *this;
100}
LayoutUnit
Layout measurement units.
Definition qgis.h:5360
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:6975