QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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  {
161  TemporalUnknownUnit
162  };
163  Q_ENUM( TemporalUnit )
164 
165 
167  {
168  RenderMillimeters = 0,
176  };
177  Q_ENUM( RenderUnit )
178 
179 
181  {
182  LayoutMillimeters = 0,
189  LayoutPixels
190  };
191  Q_ENUM( LayoutUnit )
192 
193 
195  {
196  LayoutPaperUnits = 0,
197  LayoutScreenUnits
198  };
199 
206  {
207 
211  double value;
212 
217  };
218 
224  struct AreaValue
225  {
226 
230  double value;
231 
236  };
237 
239  typedef QList<QgsUnitTypes::RenderUnit> RenderUnitList;
240 
247  Q_INVOKABLE static QString encodeUnitType( QgsUnitTypes::UnitType type );
248 
257  Q_INVOKABLE static QgsUnitTypes::UnitType decodeUnitType( const QString &string, bool *ok SIP_OUT = nullptr );
258 
259 
260  // DISTANCE UNITS
261 
265  Q_INVOKABLE static QgsUnitTypes::DistanceUnitType unitType( QgsUnitTypes::DistanceUnit unit );
266 
273  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::DistanceUnit unit );
274 
282  Q_INVOKABLE static QgsUnitTypes::DistanceUnit decodeDistanceUnit( const QString &string, bool *ok SIP_OUT = nullptr );
283 
289  Q_INVOKABLE static QString toString( QgsUnitTypes::DistanceUnit unit );
290 
298  Q_INVOKABLE static QString toAbbreviatedString( QgsUnitTypes::DistanceUnit unit );
299 
307  Q_INVOKABLE static QgsUnitTypes::DistanceUnit stringToDistanceUnit( const QString &string, bool *ok SIP_OUT = nullptr );
308 
315  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit );
316 
317  // AREAL UNITS
318 
322  Q_INVOKABLE static QgsUnitTypes::DistanceUnitType unitType( QgsUnitTypes::AreaUnit unit );
323 
330  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::AreaUnit unit );
331 
339  Q_INVOKABLE static QgsUnitTypes::AreaUnit decodeAreaUnit( const QString &string, bool *ok SIP_OUT = nullptr );
340 
346  static QString toString( QgsUnitTypes::AreaUnit unit );
347 
355  static QString toAbbreviatedString( QgsUnitTypes::AreaUnit unit );
356 
364  Q_INVOKABLE static QgsUnitTypes::AreaUnit stringToAreaUnit( const QString &string, bool *ok SIP_OUT = nullptr );
365 
372  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::AreaUnit fromUnit, QgsUnitTypes::AreaUnit toUnit );
373 
379  Q_INVOKABLE static QgsUnitTypes::AreaUnit distanceToAreaUnit( QgsUnitTypes::DistanceUnit distanceUnit );
380 
387  Q_INVOKABLE static QgsUnitTypes::DistanceUnit areaToDistanceUnit( QgsUnitTypes::AreaUnit areaUnit );
388 
389  // TEMPORAL UNITS
390 
397  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::TemporalUnit unit );
398 
407  Q_INVOKABLE static QgsUnitTypes::TemporalUnit decodeTemporalUnit( const QString &string, bool *ok SIP_OUT = nullptr );
408 
414  static QString toString( QgsUnitTypes::TemporalUnit unit );
415 
422  static QString toAbbreviatedString( QgsUnitTypes::TemporalUnit unit );
423 
432  Q_INVOKABLE static QgsUnitTypes::TemporalUnit stringToTemporalUnit( const QString &string, bool *ok SIP_OUT = nullptr );
433 
445  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::TemporalUnit fromUnit, QgsUnitTypes::TemporalUnit toUnit );
446 
447  // VOLUME UNITS
448 
453  Q_INVOKABLE static QgsUnitTypes::DistanceUnitType unitType( QgsUnitTypes::VolumeUnit unit );
454 
461  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::VolumeUnit unit );
462 
471  Q_INVOKABLE static QgsUnitTypes::VolumeUnit decodeVolumeUnit( const QString &string, bool *ok SIP_OUT = nullptr );
472 
478  static QString toString( QgsUnitTypes::VolumeUnit unit );
479 
486  static QString toAbbreviatedString( QgsUnitTypes::VolumeUnit unit );
487 
496  Q_INVOKABLE static QgsUnitTypes::VolumeUnit stringToVolumeUnit( const QString &string, bool *ok SIP_OUT = nullptr );
497 
505  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::VolumeUnit fromUnit, QgsUnitTypes::VolumeUnit toUnit );
506 
513  Q_INVOKABLE static QgsUnitTypes::VolumeUnit distanceToVolumeUnit( QgsUnitTypes::DistanceUnit distanceUnit );
514 
521  Q_INVOKABLE static QgsUnitTypes::DistanceUnit volumeToDistanceUnit( QgsUnitTypes::VolumeUnit volumeUnit );
522 
523  // ANGULAR UNITS
524 
531  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::AngleUnit unit );
532 
540  Q_INVOKABLE static QgsUnitTypes::AngleUnit decodeAngleUnit( const QString &string, bool *ok SIP_OUT = nullptr );
541 
546  static QString toString( QgsUnitTypes::AngleUnit unit );
547 
554  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::AngleUnit fromUnit, QgsUnitTypes::AngleUnit toUnit );
555 
563  Q_INVOKABLE static QString formatAngle( double angle, int decimals, QgsUnitTypes::AngleUnit unit );
564 
565 
575  Q_INVOKABLE static QgsUnitTypes::DistanceValue scaledDistance( double distance, QgsUnitTypes::DistanceUnit unit, int decimals, bool keepBaseUnit = false );
576 
586  Q_INVOKABLE static QgsUnitTypes::AreaValue scaledArea( double area, QgsUnitTypes::AreaUnit unit, int decimals, bool keepBaseUnit = false );
587 
599  Q_INVOKABLE static QString formatDistance( double distance, int decimals, QgsUnitTypes::DistanceUnit unit, bool keepBaseUnit = false );
600 
612  Q_INVOKABLE static QString formatArea( double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit = false );
613 
614  // RENDER UNITS
615 
622  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::RenderUnit unit );
623 
631  Q_INVOKABLE static QgsUnitTypes::RenderUnit decodeRenderUnit( const QString &string, bool *ok SIP_OUT = nullptr );
632 
633 
638  static QString toString( QgsUnitTypes::RenderUnit unit );
639 
646  static QString toAbbreviatedString( QgsUnitTypes::RenderUnit unit );
647 
648 
649  // LAYOUT UNITS
650 
658  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::LayoutUnit unit );
659 
668  Q_INVOKABLE static QgsUnitTypes::LayoutUnit decodeLayoutUnit( const QString &string, bool *ok SIP_OUT = nullptr );
669 
675  Q_INVOKABLE static QgsUnitTypes::LayoutUnitType unitType( QgsUnitTypes::LayoutUnit units );
676 
682  static QString toAbbreviatedString( QgsUnitTypes::LayoutUnit unit );
683 
689  static QString toString( QgsUnitTypes::LayoutUnit unit );
690 
691 };
692 
693 #endif // QGSUNITTYPES_H
QgsUnitTypes::TemporalDecades
@ TemporalDecades
Decades.
Definition: qgsunittypes.h:159
QgsUnitTypes::AreaSquareFeet
@ AreaSquareFeet
Square feet.
Definition: qgsunittypes.h:97
QgsUnitTypes::AreaSquareMiles
@ AreaSquareMiles
Square miles.
Definition: qgsunittypes.h:99
QgsUnitTypes::RenderInches
@ RenderInches
Inches.
Definition: qgsunittypes.h:173
QgsUnitTypes::ImperialSystem
@ ImperialSystem
British Imperial.
Definition: qgsunittypes.h:48
QgsUnitTypes::RenderUnit
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:166
QgsUnitTypes::LayoutUnitType
LayoutUnitType
Types of layout units.
Definition: qgsunittypes.h:194
QgsUnitTypes::DistanceUnknownUnit
@ DistanceUnknownUnit
Unknown distance unit.
Definition: qgsunittypes.h:78
QgsUnitTypes::VolumeUnit
VolumeUnit
Units of volume.
Definition: qgsunittypes.h:114
QgsUnitTypes::AngleSecondsOfArc
@ AngleSecondsOfArc
Seconds of arc.
Definition: qgsunittypes.h:137
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsUnitTypes::TemporalYears
@ TemporalYears
Years.
Definition: qgsunittypes.h:158
QgsUnitTypes::UnknownType
@ UnknownType
Unknown unit type.
Definition: qgsunittypes.h:89
QgsUnitTypes::VolumeCubicDegrees
@ VolumeCubicDegrees
Cubic degrees, for planar geographic CRS volume measurements.
Definition: qgsunittypes.h:125
QgsUnitTypes::RenderPoints
@ RenderPoints
Points (e.g., for font sizes)
Definition: qgsunittypes.h:172
QgsUnitTypes::AngleUnknownUnit
@ AngleUnknownUnit
Unknown angle unit.
Definition: qgsunittypes.h:141
QgsUnitTypes::TemporalDays
@ TemporalDays
Days.
Definition: qgsunittypes.h:155
QgsUnitTypes::LayoutUnit
LayoutUnit
Layout measurement units.
Definition: qgsunittypes.h:180
QgsUnitTypes::RenderPercentage
@ RenderPercentage
Percentage of another measurement (e.g., canvas size, feature size)
Definition: qgsunittypes.h:171
QgsUnitTypes::TypeVolume
@ TypeVolume
Volume unit.
Definition: qgsunittypes.h:61
QgsUnitTypes::LayoutFeet
@ LayoutFeet
Feet.
Definition: qgsunittypes.h:186
QgsUnitTypes::VolumeUnknownUnit
@ VolumeUnknownUnit
Unknown volume unit.
Definition: qgsunittypes.h:126
QgsUnitTypes::VolumeBarrel
@ VolumeBarrel
Barrels.
Definition: qgsunittypes.h:119
QgsUnitTypes::VolumeCubicDecimeter
@ VolumeCubicDecimeter
Cubic decimeters.
Definition: qgsunittypes.h:120
QgsUnitTypes::AngleGon
@ AngleGon
Gon/gradian.
Definition: qgsunittypes.h:135
QgsUnitTypes::TemporalUnit
TemporalUnit
Temporal units.
Definition: qgsunittypes.h:149
QgsUnitTypes::DistanceUnit
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:67
QgsUnitTypes::LayoutCentimeters
@ LayoutCentimeters
Centimeters.
Definition: qgsunittypes.h:183
QgsUnitTypes::DistanceKilometers
@ DistanceKilometers
Kilometers.
Definition: qgsunittypes.h:70
QgsUnitTypes::SystemOfMeasurement
SystemOfMeasurement
Systems of unit measurement.
Definition: qgsunittypes.h:44
QgsUnitTypes::AreaSquareKilometers
@ AreaSquareKilometers
Square kilometers.
Definition: qgsunittypes.h:96
QgsUnitTypes::AngleRadians
@ AngleRadians
Square kilometers.
Definition: qgsunittypes.h:134
QgsUnitTypes::TypeUnknown
@ TypeUnknown
Unknown unit type.
Definition: qgsunittypes.h:62
QgsUnitTypes::DistanceUnitType
DistanceUnitType
Types of distance units.
Definition: qgsunittypes.h:85
QgsUnitTypes::TemporalSeconds
@ TemporalSeconds
Seconds.
Definition: qgsunittypes.h:152
QgsUnitTypes::TypeArea
@ TypeArea
Area unit.
Definition: qgsunittypes.h:60
QgsUnitTypes::UnitType
UnitType
Unit types.
Definition: qgsunittypes.h:57
QgsUnitTypes::LayoutInches
@ LayoutInches
Inches.
Definition: qgsunittypes.h:185
QgsUnitTypes::TemporalMonths
@ TemporalMonths
Months.
Definition: qgsunittypes.h:157
QgsUnitTypes::DistanceValue::value
double value
The value part of the distance.
Definition: qgsunittypes.h:211
QgsUnitTypes::VolumeCubicCentimeter
@ VolumeCubicCentimeter
Cubic Centimeters.
Definition: qgsunittypes.h:124
QgsUnitTypes::AreaSquareYards
@ AreaSquareYards
Square yards.
Definition: qgsunittypes.h:98
QgsUnitTypes::VolumeLiters
@ VolumeLiters
Litres.
Definition: qgsunittypes.h:121
QgsUnitTypes::DistanceDegrees
@ DistanceDegrees
Degrees, for planar geographic CRS distance measurements.
Definition: qgsunittypes.h:75
QgsUnitTypes::AngleUnit
AngleUnit
Units of angles.
Definition: qgsunittypes.h:131
QgsUnitTypes::LayoutPicas
@ LayoutPicas
Typographic picas.
Definition: qgsunittypes.h:188
QgsUnitTypes::AreaValue
A combination of area value and unit.
Definition: qgsunittypes.h:224
QgsUnitTypes::AreaSquareMillimeters
@ AreaSquareMillimeters
Square millimeters.
Definition: qgsunittypes.h:105
qgis_sip.h
QgsUnitTypes::DistanceFeet
@ DistanceFeet
Imperial feet.
Definition: qgsunittypes.h:71
QgsUnitTypes
Helper functions for various unit types.
Definition: qgsunittypes.h:38
QgsUnitTypes::AreaUnit
AreaUnit
Units of area.
Definition: qgsunittypes.h:93
QgsUnitTypes::AngleMilliradiansSI
@ AngleMilliradiansSI
Angular milliradians (SI definition, 1/1000 of radian)
Definition: qgsunittypes.h:139
QgsUnitTypes::AreaHectares
@ AreaHectares
Hectares.
Definition: qgsunittypes.h:100
QgsUnitTypes::MetricSystem
@ MetricSystem
International System of Units (SI)
Definition: qgsunittypes.h:47
QgsUnitTypes::AreaValue::value
double value
The value part of the distance.
Definition: qgsunittypes.h:230
QgsUnitTypes::AreaSquareDegrees
@ AreaSquareDegrees
Square degrees, for planar geographic CRS area measurements.
Definition: qgsunittypes.h:103
QgsUnitTypes::VolumeGallonUS
@ VolumeGallonUS
US Gallons.
Definition: qgsunittypes.h:122
QgsUnitTypes::RenderPixels
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:170
QgsUnitTypes::TemporalHours
@ TemporalHours
Hours.
Definition: qgsunittypes.h:154
QgsUnitTypes::TemporalMinutes
@ TemporalMinutes
Minutes.
Definition: qgsunittypes.h:153
QgsUnitTypes::DistanceValue
A combination of distance value and unit.
Definition: qgsunittypes.h:205
QgsUnitTypes::AngleTurn
@ AngleTurn
Turn/revolutions.
Definition: qgsunittypes.h:138
QgsUnitTypes::TemporalMilliseconds
@ TemporalMilliseconds
Milliseconds.
Definition: qgsunittypes.h:151
QgsUnitTypes::AngleMinutesOfArc
@ AngleMinutesOfArc
Minutes of arc.
Definition: qgsunittypes.h:136
QgsUnitTypes::TemporalCenturies
@ TemporalCenturies
Centuries.
Definition: qgsunittypes.h:160
QgsUnitTypes::VolumeCubicInch
@ VolumeCubicInch
Cubic inches.
Definition: qgsunittypes.h:123
QgsUnitTypes::DistanceMillimeters
@ DistanceMillimeters
Millimeters.
Definition: qgsunittypes.h:77
QgsUnitTypes::TemporalWeeks
@ TemporalWeeks
Weeks.
Definition: qgsunittypes.h:156
QgsUnitTypes::DistanceCentimeters
@ DistanceCentimeters
Centimeters.
Definition: qgsunittypes.h:76
QgsUnitTypes::RenderMetersInMapUnits
@ RenderMetersInMapUnits
Meters value as Map units.
Definition: qgsunittypes.h:175
QgsUnitTypes::AngleMilNATO
@ AngleMilNATO
Angular mil (NATO definition, 6400 mil = 2PI radians)
Definition: qgsunittypes.h:140
QgsUnitTypes::RenderUnknownUnit
@ RenderUnknownUnit
Mixed or unknown units.
Definition: qgsunittypes.h:174
QgsUnitTypes::Geographic
@ Geographic
Unit is a geographic (e.g., degree based) unit.
Definition: qgsunittypes.h:88
QgsUnitTypes::DistanceYards
@ DistanceYards
Imperial yards.
Definition: qgsunittypes.h:73
QgsUnitTypes::VolumeCubicYards
@ VolumeCubicYards
Cubic yards.
Definition: qgsunittypes.h:118
QgsUnitTypes::VolumeCubicFeet
@ VolumeCubicFeet
Cubic feet.
Definition: qgsunittypes.h:117
QgsUnitTypes::DistanceMiles
@ DistanceMiles
Terrestrial miles.
Definition: qgsunittypes.h:74
QgsUnitTypes::DistanceNauticalMiles
@ DistanceNauticalMiles
Nautical miles.
Definition: qgsunittypes.h:72
QgsUnitTypes::RenderUnitList
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:239
MathUtils::angle
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
QgsUnitTypes::LayoutPoints
@ LayoutPoints
Typographic points.
Definition: qgsunittypes.h:187
QgsUnitTypes::DistanceValue::unit
QgsUnitTypes::DistanceUnit unit
The value part of the distance.
Definition: qgsunittypes.h:216
QgsUnitTypes::AreaSquareNauticalMiles
@ AreaSquareNauticalMiles
Square nautical miles.
Definition: qgsunittypes.h:102
QgsUnitTypes::RenderMapUnits
@ RenderMapUnits
Map units.
Definition: qgsunittypes.h:169
QgsUnitTypes::LayoutMeters
@ LayoutMeters
Meters.
Definition: qgsunittypes.h:184
QgsUnitTypes::TypeTemporal
@ TypeTemporal
Temporal unit.
Definition: qgsunittypes.h:63
QgsUnitTypes::AreaSquareCentimeters
@ AreaSquareCentimeters
Square centimeters.
Definition: qgsunittypes.h:104
QgsUnitTypes::AreaValue::unit
QgsUnitTypes::AreaUnit unit
The value part of the distance.
Definition: qgsunittypes.h:235
QgsUnitTypes::AreaUnknownUnit
@ AreaUnknownUnit
Unknown areal unit.
Definition: qgsunittypes.h:106
QgsUnitTypes::AreaAcres
@ AreaAcres
Acres.
Definition: qgsunittypes.h:101