QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
layout
qgslayoutsize.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgslayoutsize.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 "
qgslayoutsize.h
"
19
20
#include "
qgis.h
"
21
#include "
qgsunittypes.h
"
22
23
#include <QString>
24
#include <QStringList>
25
26
using namespace
Qt::StringLiterals;
27
28
QgsLayoutSize::QgsLayoutSize
(
const
double
width
,
const
double
height
,
const
Qgis::LayoutUnit
units
)
29
: mWidth(
width
)
30
, mHeight(
height
)
31
, mUnits(
units
)
32
{
33
#ifdef QGISDEBUG
34
Q_ASSERT_X( !std::isnan(
width
) && !std::isnan(
height
),
"QgsLayoutSize"
,
"Layout size with NaN dimensions created"
);
35
#endif
36
}
37
38
QgsLayoutSize::QgsLayoutSize
(
const
QSizeF size,
const
Qgis::LayoutUnit
units
)
39
: mWidth( size.
width
() )
40
, mHeight( size.
height
() )
41
, mUnits(
units
)
42
{}
43
44
QgsLayoutSize::QgsLayoutSize
(
const
Qgis::LayoutUnit
units
)
45
: mUnits(
units
)
46
{}
47
48
bool
QgsLayoutSize::isEmpty
()
const
49
{
50
return
qgsDoubleNear
( mWidth, 0 ) &&
qgsDoubleNear
( mHeight, 0 );
51
}
52
53
QSizeF
QgsLayoutSize::toQSizeF
()
const
54
{
55
return
QSizeF( mWidth, mHeight );
56
}
57
58
QString
QgsLayoutSize::encodeSize
()
const
59
{
60
return
u
"%1,%2,%3"
_s.arg( mWidth ).arg( mHeight ).arg(
QgsUnitTypes::encodeUnit
( mUnits ) );
61
}
62
63
QgsLayoutSize
QgsLayoutSize::decodeSize
(
const
QString &
string
)
64
{
65
QStringList parts =
string
.split(
','
);
66
if
( parts.count() != 3 )
67
{
68
return
QgsLayoutSize
();
69
}
70
71
const
double
width
= parts[0].toDouble();
72
const
double
height
= parts[1].toDouble();
73
if
( std::isnan(
width
) || std::isnan(
height
) )
74
return
QgsLayoutSize
();
75
76
return
QgsLayoutSize
(
width
,
height
,
QgsUnitTypes::decodeLayoutUnit
( parts[2] ) );
77
}
78
79
bool
QgsLayoutSize::operator==
(
const
QgsLayoutSize
&other )
const
80
{
81
return
other.
units
() == mUnits &&
qgsDoubleNear
( other.
width
(), mWidth ) &&
qgsDoubleNear
( other.
height
(), mHeight );
82
}
83
84
bool
QgsLayoutSize::operator!=
(
const
QgsLayoutSize
&other )
const
85
{
86
return
( !
operator
==( other ) );
87
}
88
89
QgsLayoutSize
QgsLayoutSize::operator*
(
const
double
v )
const
90
{
91
return
QgsLayoutSize
( mWidth * v, mHeight * v, mUnits );
92
}
93
94
QgsLayoutSize
QgsLayoutSize::operator*=
(
const
double
v )
95
{
96
*
this
= *
this
* v;
97
return
*
this
;
98
}
99
100
QgsLayoutSize
QgsLayoutSize::operator/
(
const
double
v )
const
101
{
102
return
QgsLayoutSize
( mWidth / v, mHeight / v, mUnits );
103
}
104
105
QgsLayoutSize
QgsLayoutSize::operator/=
(
const
double
v )
106
{
107
*
this
= *
this
/ v;
108
return
*
this
;
109
}
Qgis::LayoutUnit
LayoutUnit
Layout measurement units.
Definition
qgis.h:5778
QgsLayoutSize::decodeSize
static QgsLayoutSize decodeSize(const QString &string)
Decodes a size from a string.
Definition
qgslayoutsize.cpp:63
QgsLayoutSize::height
double height() const
Returns the height of the size.
Definition
qgslayoutsize.h:108
QgsLayoutSize::operator==
bool operator==(const QgsLayoutSize &other) const
Definition
qgslayoutsize.cpp:79
QgsLayoutSize::operator/=
QgsLayoutSize operator/=(double v)
Divides the width and height by a scalar value.
Definition
qgslayoutsize.cpp:105
QgsLayoutSize::units
Qgis::LayoutUnit units() const
Returns the units for the size.
Definition
qgslayoutsize.h:127
QgsLayoutSize::width
double width() const
Returns the width of the size.
Definition
qgslayoutsize.h:88
QgsLayoutSize::operator!=
bool operator!=(const QgsLayoutSize &other) const
Definition
qgslayoutsize.cpp:84
QgsLayoutSize::operator/
QgsLayoutSize operator/(double v) const
Divides the width and height by a scalar value.
Definition
qgslayoutsize.cpp:100
QgsLayoutSize::encodeSize
QString encodeSize() const
Encodes the layout size to a string.
Definition
qgslayoutsize.cpp:58
QgsLayoutSize::isEmpty
bool isEmpty() const
Tests whether the size is empty, ie both its width and height are zero.
Definition
qgslayoutsize.cpp:48
QgsLayoutSize::operator*=
QgsLayoutSize operator*=(double v)
Multiplies the width and height by a scalar value.
Definition
qgslayoutsize.cpp:94
QgsLayoutSize::QgsLayoutSize
QgsLayoutSize(double width, double height, Qgis::LayoutUnit units=Qgis::LayoutUnit::Millimeters)
Constructor for QgsLayoutSize.
Definition
qgslayoutsize.cpp:28
QgsLayoutSize::toQSizeF
QSizeF toQSizeF() const
Converts the layout size to a QSizeF.
Definition
qgslayoutsize.cpp:53
QgsLayoutSize::operator*
QgsLayoutSize operator*(double v) const
Multiplies the width and height by a scalar value.
Definition
qgslayoutsize.cpp:89
QgsUnitTypes::decodeLayoutUnit
static Q_INVOKABLE Qgis::LayoutUnit decodeLayoutUnit(const QString &string, bool *ok=nullptr)
Decodes a layout unit from a string.
Definition
qgsunittypes.cpp:3519
QgsUnitTypes::encodeUnit
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
Definition
qgsunittypes.cpp:169
qgis.h
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:7743
qgslayoutsize.h
qgsunittypes.h
Generated on
for QGIS API Documentation by
1.17.0