QGIS API Documentation 3.43.0-Master (c67cf405802)
qgslayoutsize.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutsize.h
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#ifndef QGSLAYOUTSIZE_H
19#define QGSLAYOUTSIZE_H
20
21#include "qgis_core.h"
22#include "qgis.h"
23#include "qgsconfig.h"
24#include <QSizeF>
25
26
42class CORE_EXPORT QgsLayoutSize
43{
44 public:
45
52 QgsLayoutSize( double width, double height, Qgis::LayoutUnit units = Qgis::LayoutUnit::Millimeters );
53
57 explicit QgsLayoutSize( QSizeF size, Qgis::LayoutUnit units = Qgis::LayoutUnit::Millimeters );
58
64
71 void setSize( const double width, const double height )
72 {
73 mWidth = width;
74 mHeight = height;
75#ifdef QGISDEBUG
76 Q_ASSERT_X( !std::isnan( width ) && !std::isnan( height ), "QgsLayoutSize", "Layout size with NaN dimensions created" );
77#endif
78 }
79
85 double width() const { return mWidth; }
86
92 void setWidth( const double width )
93 {
94 mWidth = width;
95#ifdef QGISDEBUG
96 Q_ASSERT_X( !std::isnan( width ), "QgsLayoutSize", "Layout size with NaN dimensions created" );
97#endif
98 }
99
105 double height() const { return mHeight; }
106
112 void setHeight( const double height )
113 {
114 mHeight = height;
115#ifdef QGISDEBUG
116 Q_ASSERT_X( !std::isnan( height ), "QgsLayoutSize", "Layout size with NaN dimensions created" );
117#endif
118 }
119
124 Qgis::LayoutUnit units() const { return mUnits; }
125
131 void setUnits( const Qgis::LayoutUnit units ) { mUnits = units; }
132
138 bool isEmpty() const;
139
145 QSizeF toQSizeF() const;
146
151 QString encodeSize() const;
152
157 static QgsLayoutSize decodeSize( const QString &string );
158
159 bool operator==( const QgsLayoutSize &other ) const;
160 bool operator!=( const QgsLayoutSize &other ) const;
161
165 QgsLayoutSize operator*( double v ) const;
166
170 QgsLayoutSize operator*=( double v );
171
175 QgsLayoutSize operator/( double v ) const;
176
180 QgsLayoutSize operator/=( double v );
181
182#ifdef SIP_RUN
183 SIP_PYOBJECT __repr__();
184 % MethodCode
185 QString str = QStringLiteral( "<QgsLayoutSize: %1 x %2 %3 >" ).arg( sipCpp->width() ).arg( sipCpp->height() ).arg( QgsUnitTypes::toAbbreviatedString( sipCpp->units() ) );
186 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
187 % End
188#endif
189
190 private:
191
192 double mWidth = 0.0;
193 double mHeight = 0.0;
195
196};
197
198#endif // QGSLAYOUTSIZE_H
LayoutUnit
Layout measurement units.
Definition qgis.h:5033
@ Millimeters
Millimeters.
Provides a method of storing sizes, consisting of a width and height, for use in QGIS layouts.
void setUnits(const Qgis::LayoutUnit units)
Sets the units for the size.
void setSize(const double width, const double height)
Sets new width and height for the size.
double height() const
Returns the height of the size.
void setWidth(const double width)
Sets the width for the size.
Qgis::LayoutUnit units() const
Returns the units for the size.
double width() const
Returns the width of the size.
void setHeight(const double height)
Sets the height for the size.
static Q_INVOKABLE QString toAbbreviatedString(Qgis::DistanceUnit unit)
Returns a translated abbreviation representing a distance unit.
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
QgsMargins operator*(const QgsMargins &margins, double factor)
Returns a QgsMargins object that is formed by multiplying each component of the given margins by fact...
Definition qgsmargins.h:249
QgsMargins operator/(const QgsMargins &margins, double divisor)
Returns a QgsMargins object that is formed by dividing the components of the given margins by the giv...
Definition qgsmargins.h:269