QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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#include "qgis.h"
20#include "qgsunittypes.h"
21
22#include <QStringList>
23
25 : mLength( length )
26 , mUnits( units )
27{
28}
29
31{
32 return QStringLiteral( "%1,%2" ).arg( mLength ).arg( QgsUnitTypes::encodeUnit( mUnits ) );
33}
34
36{
37 QStringList parts = string.split( ',' );
38 if ( parts.count() != 2 )
39 {
40 return QgsLayoutMeasurement( 0 );
41 }
42 return QgsLayoutMeasurement( parts[0].toDouble(), QgsUnitTypes::decodeLayoutUnit( parts[1] ) );
43}
44
46{
47 return other.units() == mUnits && qgsDoubleNear( other.length(), mLength );
48}
49
51{
52 return ( ! operator==( other ) );
53}
54
56{
57 return QgsLayoutMeasurement( mLength + v, mUnits );
58}
59
61{
62 *this = *this + v;
63 return *this;
64}
65
67{
68 return QgsLayoutMeasurement( mLength - v, mUnits );
69}
70
72{
73 *this = *this - v;
74 return *this;
75}
76
78{
79 return QgsLayoutMeasurement( mLength * v, mUnits );
80}
81
83{
84 *this = *this * v;
85 return *this;
86}
87
89{
90 return QgsLayoutMeasurement( mLength / v, mUnits );
91}
92
94{
95 *this = *this / v;
96 return *this;
97}
LayoutUnit
Layout measurement units.
Definition qgis.h:4859
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
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:5917