QGIS API Documentation  3.17.0-Master (a035f434f4)
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
VolumeUnit
Units of volume.
Definition: qgsunittypes.h:114
Meters value as Map units.
Definition: qgsunittypes.h:175
SystemOfMeasurement
Systems of unit measurement.
Definition: qgsunittypes.h:44
double value
The value part of the distance.
Definition: qgsunittypes.h:230
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
Helper functions for various unit types.
Definition: qgsunittypes.h:38
LayoutUnitType
Types of layout units.
Definition: qgsunittypes.h:194
DistanceUnitType
Types of distance units.
Definition: qgsunittypes.h:85
Unknown areal unit.
Definition: qgsunittypes.h:106
Mixed or unknown units.
Definition: qgsunittypes.h:174
Square kilometers.
Definition: qgsunittypes.h:134
Percentage of another measurement (e.g., canvas size, feature size)
Definition: qgsunittypes.h:171
Typographic points.
Definition: qgsunittypes.h:187
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:239
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:131
Unknown unit type.
Definition: qgsunittypes.h:62
Degrees, for planar geographic CRS distance measurements.
Definition: qgsunittypes.h:75
Cubic degrees, for planar geographic CRS volume measurements.
Definition: qgsunittypes.h:125
International System of Units (SI)
Definition: qgsunittypes.h:47
Square degrees, for planar geographic CRS area measurements.
Definition: qgsunittypes.h:103
A combination of distance value and unit.
Definition: qgsunittypes.h:205
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:67
Unknown distance unit.
Definition: qgsunittypes.h:78
QgsUnitTypes::AreaUnit unit
The value part of the distance.
Definition: qgsunittypes.h:235
Unknown angle unit.
Definition: qgsunittypes.h:141
Unknown unit type.
Definition: qgsunittypes.h:89
Unit is a geographic (e.g., degree based) unit.
Definition: qgsunittypes.h:88
Points (e.g., for font sizes)
Definition: qgsunittypes.h:172
Turn/revolutions.
Definition: qgsunittypes.h:138
#define SIP_OUT
Definition: qgis_sip.h:58
A combination of area value and unit.
Definition: qgsunittypes.h:224
LayoutUnit
Layout measurement units.
Definition: qgsunittypes.h:180
Angular milliradians (SI definition, 1/1000 of radian)
Definition: qgsunittypes.h:139
TemporalUnit
Temporal units.
Definition: qgsunittypes.h:149
Angular mil (NATO definition, 6400 mil = 2PI radians)
Definition: qgsunittypes.h:140
Unknown volume unit.
Definition: qgsunittypes.h:126
UnitType
Unit types.
Definition: qgsunittypes.h:57
Terrestrial miles.
Definition: qgsunittypes.h:74
AreaUnit
Units of area.
Definition: qgsunittypes.h:93
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:166
Typographic picas.
Definition: qgsunittypes.h:188