QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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
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:181
@ LayoutInches
Inches.
Definition: qgsunittypes.h:185
@ LayoutFeet
Feet.
Definition: qgsunittypes.h:186
@ LayoutCentimeters
Centimeters.
Definition: qgsunittypes.h:183
@ LayoutPicas
Typographic picas.
Definition: qgsunittypes.h:188
@ LayoutPoints
Typographic points.
Definition: qgsunittypes.h:187
@ LayoutMeters
Meters.
Definition: qgsunittypes.h:184
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:239
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
@ 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:167
@ RenderUnknownUnit
Mixed or unknown units.
Definition: qgsunittypes.h:174
@ RenderMetersInMapUnits
Meters value as Map units.
Definition: qgsunittypes.h:175
@ RenderPercentage
Percentage of another measurement (e.g., canvas size, feature size)
Definition: qgsunittypes.h:171
@ RenderPoints
Points (e.g., for font sizes)
Definition: qgsunittypes.h:172
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:170
@ RenderInches
Inches.
Definition: qgsunittypes.h:173
@ RenderMapUnits
Map units.
Definition: qgsunittypes.h:169
LayoutUnitType
Types of layout units.
Definition: qgsunittypes.h:195
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:225
double value
The value part of the distance.
Definition: qgsunittypes.h:230
QgsUnitTypes::AreaUnit unit
The value part of the distance.
Definition: qgsunittypes.h:235
A combination of distance value and unit.
Definition: qgsunittypes.h:206
QgsUnitTypes::DistanceUnit unit
The value part of the distance.
Definition: qgsunittypes.h:216
double value
The value part of the distance.
Definition: qgsunittypes.h:211