QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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 "qgsconfig.h"
22
23#include "qgis.h"
24#include "qgis_core.h"
25
26#include <QSizeF>
27
43class CORE_EXPORT QgsLayoutSize
44{
45 public:
46
54
59
65
72 void setSize( const double width, const double height )
73 {
74 mWidth = width;
75 mHeight = height;
76#ifdef QGISDEBUG
77 Q_ASSERT_X( !std::isnan( width ) && !std::isnan( height ), "QgsLayoutSize", "Layout size with NaN dimensions created" );
78#endif
79 }
80
86 double width() const { return mWidth; }
87
93 void setWidth( const double width )
94 {
95 mWidth = width;
96#ifdef QGISDEBUG
97 Q_ASSERT_X( !std::isnan( width ), "QgsLayoutSize", "Layout size with NaN dimensions created" );
98#endif
99 }
100
106 double height() const { return mHeight; }
107
113 void setHeight( const double height )
114 {
115 mHeight = height;
116#ifdef QGISDEBUG
117 Q_ASSERT_X( !std::isnan( height ), "QgsLayoutSize", "Layout size with NaN dimensions created" );
118#endif
119 }
120
125 Qgis::LayoutUnit units() const { return mUnits; }
126
132 void setUnits( const Qgis::LayoutUnit units ) { mUnits = units; }
133
139 bool isEmpty() const;
140
146 QSizeF toQSizeF() const;
147
152 QString encodeSize() const;
153
158 static QgsLayoutSize decodeSize( const QString &string );
159
160 bool operator==( const QgsLayoutSize &other ) const;
161 bool operator!=( const QgsLayoutSize &other ) const;
162
166 QgsLayoutSize operator*( double v ) const;
167
171 QgsLayoutSize operator*=( double v );
172
176 QgsLayoutSize operator/( double v ) const;
177
181 QgsLayoutSize operator/=( double v );
182
183#ifdef SIP_RUN
184 SIP_PYOBJECT __repr__();
185 % MethodCode
186 QString str = QStringLiteral( "<QgsLayoutSize: %1 x %2 %3 >" ).arg( sipCpp->width() ).arg( sipCpp->height() ).arg( QgsUnitTypes::toAbbreviatedString( sipCpp->units() ) );
187 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
188 % End
189#endif
190
191 private:
192
193 double mWidth = 0.0;
194 double mHeight = 0.0;
196
197};
198
199#endif // QGSLAYOUTSIZE_H
LayoutUnit
Layout measurement units.
Definition qgis.h:5203
@ Millimeters
Millimeters.
Definition qgis.h:5204
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.
QgsLayoutSize(double width, double height, Qgis::LayoutUnit units=Qgis::LayoutUnit::Millimeters)
Constructor for QgsLayoutSize.
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:250
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:270