QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgsunittypes.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsunittypes.h
3  --------------
4  begin : February 2016
5  copyright : (C) 2016 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 QGSUNITTYPES_H
19 #define QGSUNITTYPES_H
20 
21 #include "qgis_core.h"
22 #include "qgis_sip.h"
23 #include <QObject>
24 
25 /***************************************************************************
26  * This class is considered CRITICAL and any change MUST be accompanied with
27  * full unit tests in test_qgsunittypes.py.
28  * See details in QEP #17
29  ****************************************************************************/
30 
38 class CORE_EXPORT QgsUnitTypes
39 {
40  Q_GADGET
41 
42  public:
45  {
46  UnknownSystem = 0,
49  USCSSystem
50  };
51  Q_ENUM( SystemOfMeasurement )
52 
53 
57  enum UnitType
58  {
59  TypeDistance = 0,
63  };
64 
67  {
68  DistanceMeters = 0,
78  };
79  Q_ENUM( DistanceUnit )
80 
81 
85  {
86  Standard = 0,
89  };
90 
92  enum AreaUnit
93  {
94  AreaSquareMeters = 0,
106  };
107  Q_ENUM( AreaUnit )
108 
109 
114  {
115  VolumeCubicMeters = 0,
126  };
127  Q_ENUM( VolumeUnit )
128 
129 
131  {
132  AngleDegrees = 0,
141  };
142  Q_ENUM( AngleUnit )
143 
144 
146  {
147  RenderMillimeters = 0,
155  };
156  Q_ENUM( RenderUnit )
157 
158 
160  {
161  LayoutMillimeters = 0,
168  LayoutPixels
169  };
170  Q_ENUM( LayoutUnit )
171 
172 
174  {
175  LayoutPaperUnits = 0,
176  LayoutScreenUnits
177  };
178 
185  {
186 
190  double value;
191 
196  };
197 
203  struct AreaValue
204  {
205 
209  double value;
210 
215  };
216 
218  typedef QList<QgsUnitTypes::RenderUnit> RenderUnitList;
219 
226  Q_INVOKABLE static QString encodeUnitType( QgsUnitTypes::UnitType type );
227 
236  Q_INVOKABLE static QgsUnitTypes::UnitType decodeUnitType( const QString &string, bool *ok SIP_OUT = nullptr );
237 
238 
239  // DISTANCE UNITS
240 
244  Q_INVOKABLE static DistanceUnitType unitType( QgsUnitTypes::DistanceUnit unit );
245 
252  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::DistanceUnit unit );
253 
261  Q_INVOKABLE static QgsUnitTypes::DistanceUnit decodeDistanceUnit( const QString &string, bool *ok SIP_OUT = nullptr );
262 
268  Q_INVOKABLE static QString toString( QgsUnitTypes::DistanceUnit unit );
269 
277  Q_INVOKABLE static QString toAbbreviatedString( QgsUnitTypes::DistanceUnit unit );
278 
286  Q_INVOKABLE static QgsUnitTypes::DistanceUnit stringToDistanceUnit( const QString &string, bool *ok SIP_OUT = nullptr );
287 
294  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit );
295 
296  // AREAL UNITS
297 
301  Q_INVOKABLE static DistanceUnitType unitType( QgsUnitTypes::AreaUnit unit );
302 
309  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::AreaUnit unit );
310 
318  Q_INVOKABLE static AreaUnit decodeAreaUnit( const QString &string, bool *ok SIP_OUT = nullptr );
319 
325  static QString toString( QgsUnitTypes::AreaUnit unit );
326 
334  static QString toAbbreviatedString( QgsUnitTypes::AreaUnit unit );
335 
343  Q_INVOKABLE static AreaUnit stringToAreaUnit( const QString &string, bool *ok SIP_OUT = nullptr );
344 
351  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::AreaUnit fromUnit, QgsUnitTypes::AreaUnit toUnit );
352 
358  Q_INVOKABLE static QgsUnitTypes::AreaUnit distanceToAreaUnit( QgsUnitTypes::DistanceUnit distanceUnit );
359 
366  Q_INVOKABLE static QgsUnitTypes::DistanceUnit areaToDistanceUnit( QgsUnitTypes::AreaUnit areaUnit );
367 
368  // VOLUME UNITS
369 
374  Q_INVOKABLE static DistanceUnitType unitType( QgsUnitTypes::VolumeUnit unit );
375 
382  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::VolumeUnit unit );
383 
392  Q_INVOKABLE static VolumeUnit decodeVolumeUnit( const QString &string, bool *ok SIP_OUT = nullptr );
393 
399  static QString toString( QgsUnitTypes::VolumeUnit unit );
400 
407  static QString toAbbreviatedString( QgsUnitTypes::VolumeUnit unit );
408 
417  Q_INVOKABLE static VolumeUnit stringToVolumeUnit( const QString &string, bool *ok SIP_OUT = nullptr );
418 
426  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::VolumeUnit fromUnit, QgsUnitTypes::VolumeUnit toUnit );
427 
434  Q_INVOKABLE static QgsUnitTypes::VolumeUnit distanceToVolumeUnit( QgsUnitTypes::DistanceUnit distanceUnit );
435 
442  Q_INVOKABLE static QgsUnitTypes::DistanceUnit volumeToDistanceUnit( QgsUnitTypes::VolumeUnit volumeUnit );
443 
444  // ANGULAR UNITS
445 
452  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::AngleUnit unit );
453 
461  Q_INVOKABLE static QgsUnitTypes::AngleUnit decodeAngleUnit( const QString &string, bool *ok SIP_OUT = nullptr );
462 
467  static QString toString( QgsUnitTypes::AngleUnit unit );
468 
475  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::AngleUnit fromUnit, QgsUnitTypes::AngleUnit toUnit );
476 
484  Q_INVOKABLE static QString formatAngle( double angle, int decimals, QgsUnitTypes::AngleUnit unit );
485 
486 
496  Q_INVOKABLE static QgsUnitTypes::DistanceValue scaledDistance( double distance, QgsUnitTypes::DistanceUnit unit, int decimals, bool keepBaseUnit = false );
497 
507  Q_INVOKABLE static QgsUnitTypes::AreaValue scaledArea( double area, QgsUnitTypes::AreaUnit unit, int decimals, bool keepBaseUnit = false );
508 
520  Q_INVOKABLE static QString formatDistance( double distance, int decimals, QgsUnitTypes::DistanceUnit unit, bool keepBaseUnit = false );
521 
533  Q_INVOKABLE static QString formatArea( double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit = false );
534 
535  // RENDER UNITS
536 
543  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::RenderUnit unit );
544 
552  Q_INVOKABLE static QgsUnitTypes::RenderUnit decodeRenderUnit( const QString &string, bool *ok SIP_OUT = nullptr );
553 
554 
559  static QString toString( QgsUnitTypes::RenderUnit unit );
560 
567  Q_INVOKABLE static QString toAbbreviatedString( QgsUnitTypes::RenderUnit unit );
568 
569 
570  // LAYOUT UNITS
571 
579  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::LayoutUnit unit );
580 
589  Q_INVOKABLE static QgsUnitTypes::LayoutUnit decodeLayoutUnit( const QString &string, bool *ok SIP_OUT = nullptr );
590 
596  Q_INVOKABLE static QgsUnitTypes::LayoutUnitType unitType( QgsUnitTypes::LayoutUnit units );
597 
603  static QString toAbbreviatedString( QgsUnitTypes::LayoutUnit unit );
604 
610  static QString toString( QgsUnitTypes::LayoutUnit unit );
611 
612 };
613 
614 #endif // QGSUNITTYPES_H
VolumeUnit
Units of volume.
Definition: qgsunittypes.h:113
Meters value as Map units.
Definition: qgsunittypes.h:154
SystemOfMeasurement
Systems of unit measurement.
Definition: qgsunittypes.h:44
double value
The value part of the distance.
Definition: qgsunittypes.h:209
QgsUnitTypes::DistanceUnit unit
The value part of the distance.
Definition: qgsunittypes.h:195
double value
The value part of the distance.
Definition: qgsunittypes.h:190
Helper functions for various unit types.
Definition: qgsunittypes.h:38
LayoutUnitType
Types of layout units.
Definition: qgsunittypes.h:173
DistanceUnitType
Types of distance units.
Definition: qgsunittypes.h:84
Unknown areal unit.
Definition: qgsunittypes.h:105
Mixed or unknown units.
Definition: qgsunittypes.h:153
Square kilometers.
Definition: qgsunittypes.h:133
Percentage of another measurement (e.g., canvas size, feature size)
Definition: qgsunittypes.h:150
Typographic points.
Definition: qgsunittypes.h:166
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:218
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cpp:786
British Imperial.
Definition: qgsunittypes.h:48
AngleUnit
Units of angles.
Definition: qgsunittypes.h:130
Unknown unit type.
Definition: qgsunittypes.h:62
Degrees, for planar geographic CRS distance measurements.
Definition: qgsunittypes.h:74
Cubic degrees, for planar geographic CRS volume measurements.
Definition: qgsunittypes.h:124
International System of Units (SI)
Definition: qgsunittypes.h:47
Square degrees, for planar geographic CRS area measurements.
Definition: qgsunittypes.h:102
A combination of distance value and unit.
Definition: qgsunittypes.h:184
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:66
Unknown distance unit.
Definition: qgsunittypes.h:77
QgsUnitTypes::AreaUnit unit
The value part of the distance.
Definition: qgsunittypes.h:214
Unknown angle unit.
Definition: qgsunittypes.h:140
Unknown unit type.
Definition: qgsunittypes.h:88
Unit is a geographic (e.g., degree based) unit.
Definition: qgsunittypes.h:87
Points (e.g., for font sizes)
Definition: qgsunittypes.h:151
Turn/revolutions.
Definition: qgsunittypes.h:137
#define SIP_OUT
Definition: qgis_sip.h:58
A combination of area value and unit.
Definition: qgsunittypes.h:203
LayoutUnit
Layout measurement units.
Definition: qgsunittypes.h:159
Angular milliradians (SI definition, 1/1000 of radian)
Definition: qgsunittypes.h:138
Angular mil (NATO definition, 6400 mil = 2PI radians)
Definition: qgsunittypes.h:139
Unknown volume unit.
Definition: qgsunittypes.h:125
UnitType
Unit types.
Definition: qgsunittypes.h:57
Terrestrial miles.
Definition: qgsunittypes.h:73
AreaUnit
Units of area.
Definition: qgsunittypes.h:92
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:145
Typographic picas.
Definition: qgsunittypes.h:167