23 if ( measurement.
units() == targetUnits )
28 switch ( targetUnits )
30 case Qgis::LayoutUnit::Millimeters:
31 return QgsLayoutMeasurement( convertToMillimeters( measurement ), Qgis::LayoutUnit::Millimeters );
32 case Qgis::LayoutUnit::Centimeters:
33 return QgsLayoutMeasurement( convertToCentimeters( measurement ), Qgis::LayoutUnit::Centimeters );
34 case Qgis::LayoutUnit::Meters:
36 case Qgis::LayoutUnit::Inches:
38 case Qgis::LayoutUnit::Feet:
40 case Qgis::LayoutUnit::Points:
42 case Qgis::LayoutUnit::Picas:
44 case Qgis::LayoutUnit::Pixels:
49 return QgsLayoutMeasurement( convertToMillimeters( measurement ), Qgis::LayoutUnit::Millimeters );
54 if ( size.
units() == targetUnits )
63 switch ( targetUnits )
65 case Qgis::LayoutUnit::Millimeters:
66 result.
setSize( convertToMillimeters( width ), convertToMillimeters( height ) );
68 case Qgis::LayoutUnit::Centimeters:
69 result.
setSize( convertToCentimeters( width ), convertToCentimeters( height ) );
71 case Qgis::LayoutUnit::Meters:
72 result.
setSize( convertToMeters( width ), convertToMeters( height ) );
74 case Qgis::LayoutUnit::Inches:
75 result.
setSize( convertToInches( width ), convertToInches( height ) );
77 case Qgis::LayoutUnit::Feet:
78 result.
setSize( convertToFeet( width ), convertToFeet( height ) );
80 case Qgis::LayoutUnit::Points:
81 result.
setSize( convertToPoints( width ), convertToPoints( height ) );
83 case Qgis::LayoutUnit::Picas:
84 result.
setSize( convertToPicas( width ), convertToPicas( height ) );
86 case Qgis::LayoutUnit::Pixels:
87 result.
setSize( convertToPixels( width ), convertToPixels( height ) );
95 if ( point.
units() == targetUnits )
104 switch ( targetUnits )
106 case Qgis::LayoutUnit::Millimeters:
107 result.
setPoint( convertToMillimeters( x ), convertToMillimeters( y ) );
109 case Qgis::LayoutUnit::Centimeters:
110 result.
setPoint( convertToCentimeters( x ), convertToCentimeters( y ) );
112 case Qgis::LayoutUnit::Meters:
113 result.
setPoint( convertToMeters( x ), convertToMeters( y ) );
115 case Qgis::LayoutUnit::Inches:
116 result.
setPoint( convertToInches( x ), convertToInches( y ) );
118 case Qgis::LayoutUnit::Feet:
119 result.
setPoint( convertToFeet( x ), convertToFeet( y ) );
121 case Qgis::LayoutUnit::Points:
122 result.
setPoint( convertToPoints( x ), convertToPoints( y ) );
124 case Qgis::LayoutUnit::Picas:
125 result.
setPoint( convertToPicas( x ), convertToPicas( y ) );
127 case Qgis::LayoutUnit::Pixels:
128 result.
setPoint( convertToPixels( x ), convertToPixels( y ) );
134double QgsLayoutMeasurementConverter::convertToMillimeters(
const QgsLayoutMeasurement measurement )
const
136 switch ( measurement.
units() )
138 case Qgis::LayoutUnit::Millimeters:
139 return measurement.
length();
140 case Qgis::LayoutUnit::Centimeters:
141 return measurement.
length() * 10.0;
142 case Qgis::LayoutUnit::Meters:
143 return measurement.
length() * 1000.0;
144 case Qgis::LayoutUnit::Inches:
145 return measurement.
length() * 25.4;
146 case Qgis::LayoutUnit::Feet:
147 return measurement.
length() * 304.8;
148 case Qgis::LayoutUnit::Points:
149 return measurement.
length() * 0.352777778;
150 case Qgis::LayoutUnit::Picas:
151 return measurement.
length() * 4.23333333;
152 case Qgis::LayoutUnit::Pixels:
153 return measurement.
length() * 25.4 / mDpi;
157 return measurement.
length();
160double QgsLayoutMeasurementConverter::convertToCentimeters(
const QgsLayoutMeasurement measurement )
const
162 return convertToMillimeters( measurement ) / 10.0;
165double QgsLayoutMeasurementConverter::convertToMeters(
const QgsLayoutMeasurement measurement )
const
167 return convertToMillimeters( measurement ) / 1000.0;
170double QgsLayoutMeasurementConverter::convertToInches(
const QgsLayoutMeasurement measurement )
const
172 return convertToMillimeters( measurement ) / 25.4;
175double QgsLayoutMeasurementConverter::convertToFeet(
const QgsLayoutMeasurement measurement )
const
177 return convertToMillimeters( measurement ) / 304.8;
180double QgsLayoutMeasurementConverter::convertToPoints(
const QgsLayoutMeasurement measurement )
const
182 return convertToMillimeters( measurement ) * 2.83464567;
185double QgsLayoutMeasurementConverter::convertToPicas(
const QgsLayoutMeasurement measurement )
const
187 return convertToMillimeters( measurement ) * 0.236220472;
190double QgsLayoutMeasurementConverter::convertToPixels(
const QgsLayoutMeasurement measurement )
const
192 return convertToMillimeters( measurement ) * mDpi / 25.4;
LayoutUnit
Layout measurement units.
QgsLayoutMeasurement convert(QgsLayoutMeasurement measurement, Qgis::LayoutUnit targetUnits) const
Converts a measurement from one unit to another.
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
Qgis::LayoutUnit units() const
Returns the units for the measurement.
double length() const
Returns the length of the measurement.
This class provides a method of storing points, consisting of an x and y coordinate,...
double x() const
Returns x coordinate of point.
void setUnits(const Qgis::LayoutUnit units)
Sets the units for the point.
double y() const
Returns y coordinate of point.
Qgis::LayoutUnit units() const
Returns the units for the point.
void setPoint(const double x, const double y)
Sets new x and y coordinates for the point.
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
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.
Qgis::LayoutUnit units() const
Returns the units for the size.
double width() const
Returns the width of the size.