QGIS API Documentation  3.20.0-Odense (decaadbb31)
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,
64  };
65 
68  {
69  DistanceMeters = 0,
79  };
80  Q_ENUM( DistanceUnit )
81 
82 
86  {
87  Standard = 0,
90  };
91 
93  enum AreaUnit
94  {
95  AreaSquareMeters = 0,
107  };
108  Q_ENUM( AreaUnit )
109 
110 
115  {
116  VolumeCubicMeters = 0,
127  };
128  Q_ENUM( VolumeUnit )
129 
130 
132  {
133  AngleDegrees = 0,
142  };
143  Q_ENUM( AngleUnit )
144 
145 
150  {
162  TemporalUnknownUnit
163  };
164  Q_ENUM( TemporalUnit )
165 
166 
168  {
169  RenderMillimeters = 0,
177  };
178  Q_ENUM( RenderUnit )
179 
180 
182  {
183  LayoutMillimeters = 0,
190  LayoutPixels
191  };
192  Q_ENUM( LayoutUnit )
193 
194 
196  {
197  LayoutPaperUnits = 0,
198  LayoutScreenUnits
199  };
200 
207  {
208 
212  double value;
213 
218  };
219 
225  struct AreaValue
226  {
227 
231  double value;
232 
237  };
238 
240  typedef QList<QgsUnitTypes::RenderUnit> RenderUnitList;
241 
248  Q_INVOKABLE static QString encodeUnitType( QgsUnitTypes::UnitType type );
249 
258  Q_INVOKABLE static QgsUnitTypes::UnitType decodeUnitType( const QString &string, bool *ok SIP_OUT = nullptr );
259 
260 
261  // DISTANCE UNITS
262 
266  Q_INVOKABLE static QgsUnitTypes::DistanceUnitType unitType( QgsUnitTypes::DistanceUnit unit );
267 
274  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::DistanceUnit unit );
275 
283  Q_INVOKABLE static QgsUnitTypes::DistanceUnit decodeDistanceUnit( const QString &string, bool *ok SIP_OUT = nullptr );
284 
290  Q_INVOKABLE static QString toString( QgsUnitTypes::DistanceUnit unit );
291 
299  Q_INVOKABLE static QString toAbbreviatedString( QgsUnitTypes::DistanceUnit unit );
300 
308  Q_INVOKABLE static QgsUnitTypes::DistanceUnit stringToDistanceUnit( const QString &string, bool *ok SIP_OUT = nullptr );
309 
316  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit );
317 
318  // AREAL UNITS
319 
324 
331  static QString encodeUnit( QgsUnitTypes::AreaUnit unit );
332 
340  Q_INVOKABLE static QgsUnitTypes::AreaUnit decodeAreaUnit( const QString &string, bool *ok SIP_OUT = nullptr );
341 
347  static QString toString( QgsUnitTypes::AreaUnit unit );
348 
356  static QString toAbbreviatedString( QgsUnitTypes::AreaUnit unit );
357 
365  Q_INVOKABLE static QgsUnitTypes::AreaUnit stringToAreaUnit( const QString &string, bool *ok SIP_OUT = nullptr );
366 
373  static double fromUnitToUnitFactor( QgsUnitTypes::AreaUnit fromUnit, QgsUnitTypes::AreaUnit toUnit );
374 
380  Q_INVOKABLE static QgsUnitTypes::AreaUnit distanceToAreaUnit( QgsUnitTypes::DistanceUnit distanceUnit );
381 
388  Q_INVOKABLE static QgsUnitTypes::DistanceUnit areaToDistanceUnit( QgsUnitTypes::AreaUnit areaUnit );
389 
390  // TEMPORAL UNITS
391 
398  static QString encodeUnit( QgsUnitTypes::TemporalUnit unit );
399 
408  Q_INVOKABLE static QgsUnitTypes::TemporalUnit decodeTemporalUnit( const QString &string, bool *ok SIP_OUT = nullptr );
409 
415  static QString toString( QgsUnitTypes::TemporalUnit unit );
416 
423  static QString toAbbreviatedString( QgsUnitTypes::TemporalUnit unit );
424 
433  Q_INVOKABLE static QgsUnitTypes::TemporalUnit stringToTemporalUnit( const QString &string, bool *ok SIP_OUT = nullptr );
434 
446  static double fromUnitToUnitFactor( QgsUnitTypes::TemporalUnit fromUnit, QgsUnitTypes::TemporalUnit toUnit );
447 
448  // VOLUME UNITS
449 
455 
462  static QString encodeUnit( QgsUnitTypes::VolumeUnit unit );
463 
472  Q_INVOKABLE static QgsUnitTypes::VolumeUnit decodeVolumeUnit( const QString &string, bool *ok SIP_OUT = nullptr );
473 
479  static QString toString( QgsUnitTypes::VolumeUnit unit );
480 
487  static QString toAbbreviatedString( QgsUnitTypes::VolumeUnit unit );
488 
497  Q_INVOKABLE static QgsUnitTypes::VolumeUnit stringToVolumeUnit( const QString &string, bool *ok SIP_OUT = nullptr );
498 
506  static double fromUnitToUnitFactor( QgsUnitTypes::VolumeUnit fromUnit, QgsUnitTypes::VolumeUnit toUnit );
507 
514  Q_INVOKABLE static QgsUnitTypes::VolumeUnit distanceToVolumeUnit( QgsUnitTypes::DistanceUnit distanceUnit );
515 
522  Q_INVOKABLE static QgsUnitTypes::DistanceUnit volumeToDistanceUnit( QgsUnitTypes::VolumeUnit volumeUnit );
523 
524  // ANGULAR UNITS
525 
532  static QString encodeUnit( QgsUnitTypes::AngleUnit unit );
533 
541  Q_INVOKABLE static QgsUnitTypes::AngleUnit decodeAngleUnit( const QString &string, bool *ok SIP_OUT = nullptr );
542 
547  static QString toString( QgsUnitTypes::AngleUnit unit );
548 
555  static double fromUnitToUnitFactor( QgsUnitTypes::AngleUnit fromUnit, QgsUnitTypes::AngleUnit toUnit );
556 
564  Q_INVOKABLE static QString formatAngle( double angle, int decimals, QgsUnitTypes::AngleUnit unit );
565 
566 
576  Q_INVOKABLE static QgsUnitTypes::DistanceValue scaledDistance( double distance, QgsUnitTypes::DistanceUnit unit, int decimals, bool keepBaseUnit = false );
577 
587  Q_INVOKABLE static QgsUnitTypes::AreaValue scaledArea( double area, QgsUnitTypes::AreaUnit unit, int decimals, bool keepBaseUnit = false );
588 
600  Q_INVOKABLE static QString formatDistance( double distance, int decimals, QgsUnitTypes::DistanceUnit unit, bool keepBaseUnit = false );
601 
613  Q_INVOKABLE static QString formatArea( double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit = false );
614 
615  // RENDER UNITS
616 
623  static QString encodeUnit( QgsUnitTypes::RenderUnit unit );
624 
632  Q_INVOKABLE static QgsUnitTypes::RenderUnit decodeRenderUnit( const QString &string, bool *ok SIP_OUT = nullptr );
633 
634 
639  static QString toString( QgsUnitTypes::RenderUnit unit );
640 
647  static QString toAbbreviatedString( QgsUnitTypes::RenderUnit unit );
648 
649 
650  // LAYOUT UNITS
651 
659  static QString encodeUnit( QgsUnitTypes::LayoutUnit unit );
660 
669  Q_INVOKABLE static QgsUnitTypes::LayoutUnit decodeLayoutUnit( const QString &string, bool *ok SIP_OUT = nullptr );
670 
676  Q_INVOKABLE static QgsUnitTypes::LayoutUnitType unitType( QgsUnitTypes::LayoutUnit units );
677 
683  static QString toAbbreviatedString( QgsUnitTypes::LayoutUnit unit );
684 
690  static QString toString( QgsUnitTypes::LayoutUnit unit );
691 
692 };
693 
694 #endif // QGSUNITTYPES_H
Helper functions for various unit types.
Definition: qgsunittypes.h:39
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:68
@ DistanceDegrees
Degrees, for planar geographic CRS distance measurements.
Definition: qgsunittypes.h:75
@ DistanceKilometers
Kilometers.
Definition: qgsunittypes.h:70
@ DistanceMiles
Terrestrial miles.
Definition: qgsunittypes.h:74
@ DistanceUnknownUnit
Unknown distance unit.
Definition: qgsunittypes.h:78
@ DistanceMillimeters
Millimeters.
Definition: qgsunittypes.h:77
@ DistanceYards
Imperial yards.
Definition: qgsunittypes.h:73
@ DistanceFeet
Imperial feet.
Definition: qgsunittypes.h:71
@ DistanceNauticalMiles
Nautical miles.
Definition: qgsunittypes.h:72
@ DistanceCentimeters
Centimeters.
Definition: qgsunittypes.h:76
LayoutUnit
Layout measurement units.
Definition: qgsunittypes.h:182
@ LayoutInches
Inches.
Definition: qgsunittypes.h:186
@ LayoutFeet
Feet.
Definition: qgsunittypes.h:187
@ LayoutCentimeters
Centimeters.
Definition: qgsunittypes.h:184
@ LayoutPicas
Typographic picas.
Definition: qgsunittypes.h:189
@ LayoutPoints
Typographic points.
Definition: qgsunittypes.h:188
@ LayoutMeters
Meters.
Definition: qgsunittypes.h:185
AngleUnit
Units of angles.
Definition: qgsunittypes.h:132
@ AngleGon
Gon/gradian.
Definition: qgsunittypes.h:135
@ AngleRadians
Square kilometers.
Definition: qgsunittypes.h:134
@ AngleMilNATO
Angular mil (NATO definition, 6400 mil = 2PI radians)
Definition: qgsunittypes.h:140
@ AngleMilliradiansSI
Angular milliradians (SI definition, 1/1000 of radian)
Definition: qgsunittypes.h:139
@ AngleTurn
Turn/revolutions.
Definition: qgsunittypes.h:138
@ AngleUnknownUnit
Unknown angle unit.
Definition: qgsunittypes.h:141
@ AngleMinutesOfArc
Minutes of arc.
Definition: qgsunittypes.h:136
@ AngleSecondsOfArc
Seconds of arc.
Definition: qgsunittypes.h:137
SystemOfMeasurement
Systems of unit measurement.
Definition: qgsunittypes.h:45
@ MetricSystem
International System of Units (SI)
Definition: qgsunittypes.h:47
@ ImperialSystem
British Imperial.
Definition: qgsunittypes.h:48
VolumeUnit
Units of volume.
Definition: qgsunittypes.h:115
@ VolumeBarrel
Barrels.
Definition: qgsunittypes.h:119
@ VolumeCubicYards
Cubic yards.
Definition: qgsunittypes.h:118
@ VolumeCubicDecimeter
Cubic decimeters.
Definition: qgsunittypes.h:120
@ VolumeCubicCentimeter
Cubic Centimeters.
Definition: qgsunittypes.h:124
@ VolumeCubicDegrees
Cubic degrees, for planar geographic CRS volume measurements.
Definition: qgsunittypes.h:125
@ VolumeCubicFeet
Cubic feet.
Definition: qgsunittypes.h:117
@ VolumeLiters
Litres.
Definition: qgsunittypes.h:121
@ VolumeCubicInch
Cubic inches.
Definition: qgsunittypes.h:123
@ VolumeUnknownUnit
Unknown volume unit.
Definition: qgsunittypes.h:126
@ VolumeGallonUS
US Gallons.
Definition: qgsunittypes.h:122
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:240
DistanceUnitType
Types of distance units.
Definition: qgsunittypes.h:86
@ Geographic
Unit is a geographic (e.g., degree based) unit.
Definition: qgsunittypes.h:88
@ UnknownType
Unknown unit type.
Definition: qgsunittypes.h:89
UnitType
Unit types.
Definition: qgsunittypes.h:58
@ TypeTemporal
Temporal unit.
Definition: qgsunittypes.h:63
@ TypeArea
Area unit.
Definition: qgsunittypes.h:60
@ TypeVolume
Volume unit.
Definition: qgsunittypes.h:61
@ TypeUnknown
Unknown unit type.
Definition: qgsunittypes.h:62
AreaUnit
Units of area.
Definition: qgsunittypes.h:94
@ AreaSquareNauticalMiles
Square nautical miles.
Definition: qgsunittypes.h:102
@ AreaSquareYards
Square yards.
Definition: qgsunittypes.h:98
@ AreaSquareFeet
Square feet.
Definition: qgsunittypes.h:97
@ AreaHectares
Hectares.
Definition: qgsunittypes.h:100
@ AreaUnknownUnit
Unknown areal unit.
Definition: qgsunittypes.h:106
@ AreaSquareMiles
Square miles.
Definition: qgsunittypes.h:99
@ AreaSquareCentimeters
Square centimeters.
Definition: qgsunittypes.h:104
@ AreaSquareKilometers
Square kilometers.
Definition: qgsunittypes.h:96
@ AreaSquareDegrees
Square degrees, for planar geographic CRS area measurements.
Definition: qgsunittypes.h:103
@ AreaAcres
Acres.
Definition: qgsunittypes.h:101
@ AreaSquareMillimeters
Square millimeters.
Definition: qgsunittypes.h:105
TemporalUnit
Temporal units.
Definition: qgsunittypes.h:150
@ TemporalMonths
Months.
Definition: qgsunittypes.h:157
@ TemporalWeeks
Weeks.
Definition: qgsunittypes.h:156
@ TemporalMilliseconds
Milliseconds.
Definition: qgsunittypes.h:151
@ TemporalIrregularStep
Special "irregular step" time unit, used for temporal data which uses irregular, non-real-world unit ...
Definition: qgsunittypes.h:161
@ TemporalDays
Days.
Definition: qgsunittypes.h:155
@ TemporalDecades
Decades.
Definition: qgsunittypes.h:159
@ TemporalCenturies
Centuries.
Definition: qgsunittypes.h:160
@ TemporalSeconds
Seconds.
Definition: qgsunittypes.h:152
@ TemporalMinutes
Minutes.
Definition: qgsunittypes.h:153
@ TemporalYears
Years.
Definition: qgsunittypes.h:158
@ TemporalHours
Hours.
Definition: qgsunittypes.h:154
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:168
@ RenderUnknownUnit
Mixed or unknown units.
Definition: qgsunittypes.h:175
@ RenderMetersInMapUnits
Meters value as Map units.
Definition: qgsunittypes.h:176
@ RenderPercentage
Percentage of another measurement (e.g., canvas size, feature size)
Definition: qgsunittypes.h:172
@ RenderPoints
Points (e.g., for font sizes)
Definition: qgsunittypes.h:173
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:171
@ RenderInches
Inches.
Definition: qgsunittypes.h:174
@ RenderMapUnits
Map units.
Definition: qgsunittypes.h:170
LayoutUnitType
Types of layout units.
Definition: qgsunittypes.h:196
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
#define SIP_OUT
Definition: qgis_sip.h:58
A combination of area value and unit.
Definition: qgsunittypes.h:226
double value
The value part of the distance.
Definition: qgsunittypes.h:231
QgsUnitTypes::AreaUnit unit
The value part of the distance.
Definition: qgsunittypes.h:236
A combination of distance value and unit.
Definition: qgsunittypes.h:207
QgsUnitTypes::DistanceUnit unit
The value part of the distance.
Definition: qgsunittypes.h:217
double value
The value part of the distance.
Definition: qgsunittypes.h:212