QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 #include "qgis.h"
20 #include <QStringList>
21 
23  : mLength( length )
24  , mUnits( units )
25 {
26 }
27 
29 {
30  return QStringLiteral( "%1,%2" ).arg( mLength ).arg( QgsUnitTypes::encodeUnit( mUnits ) );
31 }
32 
34 {
35  QStringList parts = string.split( ',' );
36  if ( parts.count() != 2 )
37  {
38  return QgsLayoutMeasurement( 0 );
39  }
40  return QgsLayoutMeasurement( parts[0].toDouble(), QgsUnitTypes::decodeLayoutUnit( parts[1] ) );
41 }
42 
44 {
45  return other.units() == mUnits && qgsDoubleNear( other.length(), mLength );
46 }
47 
49 {
50  return ( ! operator==( other ) );
51 }
52 
54 {
55  return QgsLayoutMeasurement( mLength + v, mUnits );
56 }
57 
59 {
60  *this = *this + v;
61  return *this;
62 }
63 
65 {
66  return QgsLayoutMeasurement( mLength - v, mUnits );
67 }
68 
70 {
71  *this = *this - v;
72  return *this;
73 }
74 
76 {
77  return QgsLayoutMeasurement( mLength * v, mUnits );
78 }
79 
81 {
82  *this = *this * v;
83  return *this;
84 }
85 
87 {
88  return QgsLayoutMeasurement( mLength / v, mUnits );
89 }
90 
92 {
93  *this = *this / v;
94  return *this;
95 }
QgsLayoutMeasurement::operator+=
QgsLayoutMeasurement operator+=(double v)
Adds a scalar value to the measurement.
Definition: qgslayoutmeasurement.cpp:58
QgsLayoutMeasurement::length
double length() const
Returns the length of the measurement.
Definition: qgslayoutmeasurement.h:48
QgsUnitTypes::LayoutUnit
LayoutUnit
Layout measurement units.
Definition: qgsunittypes.h:181
qgis.h
QgsLayoutMeasurement::encodeMeasurement
QString encodeMeasurement() const
Encodes the layout measurement to a string.
Definition: qgslayoutmeasurement.cpp:28
QgsLayoutMeasurement::operator==
bool operator==(QgsLayoutMeasurement other) const
Definition: qgslayoutmeasurement.cpp:43
QgsLayoutMeasurement::operator/=
QgsLayoutMeasurement operator/=(double v)
Divides the measurement by a scalar value.
Definition: qgslayoutmeasurement.cpp:91
QgsLayoutMeasurement::operator+
QgsLayoutMeasurement operator+(double v) const
Adds a scalar value to the measurement.
Definition: qgslayoutmeasurement.cpp:53
QgsUnitTypes::encodeUnit
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
Definition: qgsunittypes.cpp:122
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:315
QgsLayoutMeasurement::operator-
QgsLayoutMeasurement operator-(double v) const
Subtracts a scalar value from the measurement.
Definition: qgslayoutmeasurement.cpp:64
QgsLayoutMeasurement::units
QgsUnitTypes::LayoutUnit units() const
Returns the units for the measurement.
Definition: qgslayoutmeasurement.h:60
QgsLayoutMeasurement::operator/
QgsLayoutMeasurement operator/(double v) const
Divides the measurement by a scalar value.
Definition: qgslayoutmeasurement.cpp:86
QgsLayoutMeasurement::operator*=
QgsLayoutMeasurement operator*=(double v)
Multiplies the measurement by a scalar value.
Definition: qgslayoutmeasurement.cpp:80
qgslayoutmeasurement.h
QgsLayoutMeasurement::operator-=
QgsLayoutMeasurement operator-=(double v)
Subtracts a scalar value from the measurement.
Definition: qgslayoutmeasurement.cpp:69
QgsLayoutMeasurement::operator*
QgsLayoutMeasurement operator*(double v) const
Multiplies the measurement by a scalar value.
Definition: qgslayoutmeasurement.cpp:75
QgsUnitTypes::decodeLayoutUnit
static Q_INVOKABLE QgsUnitTypes::LayoutUnit decodeLayoutUnit(const QString &string, bool *ok=nullptr)
Decodes a layout unit from a string.
Definition: qgsunittypes.cpp:2995
QgsLayoutMeasurement::QgsLayoutMeasurement
QgsLayoutMeasurement(double length, QgsUnitTypes::LayoutUnit units=QgsUnitTypes::LayoutMillimeters)
Constructor for QgsLayoutMeasurement.
Definition: qgslayoutmeasurement.cpp:22
QgsLayoutMeasurement
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
Definition: qgslayoutmeasurement.h:34
QgsLayoutMeasurement::operator!=
bool operator!=(QgsLayoutMeasurement other) const
Definition: qgslayoutmeasurement.cpp:48
QgsLayoutMeasurement::decodeMeasurement
static QgsLayoutMeasurement decodeMeasurement(const QString &string)
Decodes a measurement from a string.
Definition: qgslayoutmeasurement.cpp:33