23 if ( measurement.
units() == targetUnits )
28 switch ( targetUnits )
54 if ( size.
units() == targetUnits )
63 switch ( targetUnits )
66 result.
setSize( convertToMillimeters( width ), convertToMillimeters( height ) );
69 result.
setSize( convertToCentimeters( width ), convertToCentimeters( height ) );
72 result.
setSize( convertToMeters( width ), convertToMeters( height ) );
75 result.
setSize( convertToInches( width ), convertToInches( height ) );
78 result.
setSize( convertToFeet( width ), convertToFeet( height ) );
81 result.
setSize( convertToPoints( width ), convertToPoints( height ) );
84 result.
setSize( convertToPicas( width ), convertToPicas( height ) );
87 result.
setSize( convertToPixels( width ), convertToPixels( height ) );
95 if ( point.
units() == targetUnits )
104 switch ( targetUnits )
107 result.
setPoint( convertToMillimeters( x ), convertToMillimeters( y ) );
110 result.
setPoint( convertToCentimeters( x ), convertToCentimeters( y ) );
113 result.
setPoint( convertToMeters( x ), convertToMeters( y ) );
116 result.
setPoint( convertToInches( x ), convertToInches( y ) );
119 result.
setPoint( convertToFeet( x ), convertToFeet( y ) );
122 result.
setPoint( convertToPoints( x ), convertToPoints( y ) );
125 result.
setPoint( convertToPicas( x ), convertToPicas( y ) );
128 result.
setPoint( convertToPixels( x ), convertToPixels( y ) );
134 double QgsLayoutMeasurementConverter::convertToMillimeters(
const QgsLayoutMeasurement measurement )
const
136 switch ( measurement.
units() )
139 return measurement.
length();
141 return measurement.
length() * 10.0;
143 return measurement.
length() * 1000.0;
145 return measurement.
length() * 25.4;
147 return measurement.
length() * 304.8;
149 return measurement.
length() * 0.352777778;
151 return measurement.
length() * 4.23333333;
153 return measurement.
length() * 25.4 / mDpi;
157 return measurement.
length();
160 double QgsLayoutMeasurementConverter::convertToCentimeters(
const QgsLayoutMeasurement measurement )
const
162 return convertToMillimeters( measurement ) / 10.0;
165 double QgsLayoutMeasurementConverter::convertToMeters(
const QgsLayoutMeasurement measurement )
const
167 return convertToMillimeters( measurement ) / 1000.0;
170 double QgsLayoutMeasurementConverter::convertToInches(
const QgsLayoutMeasurement measurement )
const
172 return convertToMillimeters( measurement ) / 25.4;
175 double QgsLayoutMeasurementConverter::convertToFeet(
const QgsLayoutMeasurement measurement )
const
177 return convertToMillimeters( measurement ) / 304.8;
180 double QgsLayoutMeasurementConverter::convertToPoints(
const QgsLayoutMeasurement measurement )
const
182 return convertToMillimeters( measurement ) * 2.83464567;
185 double QgsLayoutMeasurementConverter::convertToPicas(
const QgsLayoutMeasurement measurement )
const
187 return convertToMillimeters( measurement ) * 0.236220472;
190 double QgsLayoutMeasurementConverter::convertToPixels(
const QgsLayoutMeasurement measurement )
const
192 return convertToMillimeters( measurement ) * mDpi / 25.4;
QgsLayoutMeasurement convert(QgsLayoutMeasurement measurement, QgsUnitTypes::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...
double length() const
Returns the length of the measurement.
QgsUnitTypes::LayoutUnit units() const
Returns the units for 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 QgsUnitTypes::LayoutUnit units)
Sets the units for the point.
QgsUnitTypes::LayoutUnit units() const
Returns the units for the point.
double y() const
Returns y coordinate of 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 QgsUnitTypes::LayoutUnit units)
Sets the units for the size.
void setSize(const double width, const double height)
Sets new width and height for the size.
QgsUnitTypes::LayoutUnit units() const
Returns the units for the size.
double height() const
Returns the height of the size.
double width() const
Returns the width of the size.
LayoutUnit
Layout measurement units.
@ LayoutMillimeters
Millimeters.
@ LayoutCentimeters
Centimeters.
@ LayoutPicas
Typographic picas.
@ LayoutPoints
Typographic points.