QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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.h"
23 
24 /***************************************************************************
25  * This class is considered CRITICAL and any change MUST be accompanied with
26  * full unit tests in test_qgsunittypes.py.
27  * See details in QEP #17
28  ****************************************************************************/
29 
37 class CORE_EXPORT QgsUnitTypes
38 {
39  Q_GADGET
40 
41  public:
44  {
45  UnknownSystem = 0,
48  USCSSystem
49  };
50  Q_ENUM( SystemOfMeasurement )
51 
52 
54  {
55  DistanceMeters = 0,
65  };
66  Q_ENUM( DistanceUnit )
67 
68 
72  {
73  Standard = 0,
76  };
77 
79  enum AreaUnit
80  {
81  AreaSquareMeters = 0,
93  };
94  Q_ENUM( AreaUnit )
95 
96 
97  enum AngleUnit
98  {
99  AngleDegrees = 0,
106  };
107  Q_ENUM( AngleUnit )
108 
109 
111  {
112  RenderMillimeters = 0,
120  };
121  Q_ENUM( RenderUnit )
122 
123 
125  {
126  LayoutMillimeters = 0,
133  LayoutPixels
134  };
135  Q_ENUM( LayoutUnit )
136 
137 
139  {
140  LayoutPaperUnits = 0,
141  LayoutScreenUnits
142  };
143 
150  {
151 
155  double value;
156 
161  };
162 
168  struct AreaValue
169  {
170 
174  double value;
175 
180  };
181 
183  typedef QList<QgsUnitTypes::RenderUnit> RenderUnitList;
184 
185  // DISTANCE UNITS
186 
190  Q_INVOKABLE static DistanceUnitType unitType( QgsUnitTypes::DistanceUnit unit );
191 
198  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::DistanceUnit unit );
199 
207  Q_INVOKABLE static QgsUnitTypes::DistanceUnit decodeDistanceUnit( const QString &string, bool *ok SIP_OUT = nullptr );
208 
214  Q_INVOKABLE static QString toString( QgsUnitTypes::DistanceUnit unit );
215 
223  Q_INVOKABLE static QString toAbbreviatedString( QgsUnitTypes::DistanceUnit unit );
224 
231  Q_INVOKABLE static QgsUnitTypes::DistanceUnit stringToDistanceUnit( const QString &string, bool *ok SIP_OUT = nullptr );
232 
239  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit );
240 
241  // AREAL UNITS
242 
246  Q_INVOKABLE static DistanceUnitType unitType( QgsUnitTypes::AreaUnit unit );
247 
254  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::AreaUnit unit );
255 
263  Q_INVOKABLE static AreaUnit decodeAreaUnit( const QString &string, bool *ok SIP_OUT = nullptr );
264 
270  static QString toString( QgsUnitTypes::AreaUnit unit );
271 
279  static QString toAbbreviatedString( QgsUnitTypes::AreaUnit unit );
280 
287  Q_INVOKABLE static AreaUnit stringToAreaUnit( const QString &string, bool *ok SIP_OUT = nullptr );
288 
295  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::AreaUnit fromUnit, QgsUnitTypes::AreaUnit toUnit );
296 
302  Q_INVOKABLE static QgsUnitTypes::AreaUnit distanceToAreaUnit( QgsUnitTypes::DistanceUnit distanceUnit );
303 
304  // ANGULAR UNITS
305 
312  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::AngleUnit unit );
313 
321  Q_INVOKABLE static QgsUnitTypes::AngleUnit decodeAngleUnit( const QString &string, bool *ok SIP_OUT = nullptr );
322 
327  static QString toString( QgsUnitTypes::AngleUnit unit );
328 
335  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::AngleUnit fromUnit, QgsUnitTypes::AngleUnit toUnit );
336 
344  Q_INVOKABLE static QString formatAngle( double angle, int decimals, QgsUnitTypes::AngleUnit unit );
345 
346 
356  Q_INVOKABLE static QgsUnitTypes::DistanceValue scaledDistance( double distance, QgsUnitTypes::DistanceUnit unit, int decimals, bool keepBaseUnit = false );
357 
367  Q_INVOKABLE static QgsUnitTypes::AreaValue scaledArea( double area, QgsUnitTypes::AreaUnit unit, int decimals, bool keepBaseUnit = false );
368 
380  Q_INVOKABLE static QString formatDistance( double distance, int decimals, QgsUnitTypes::DistanceUnit unit, bool keepBaseUnit = false );
381 
393  Q_INVOKABLE static QString formatArea( double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit = false );
394 
395  // RENDER UNITS
396 
403  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::RenderUnit unit );
404 
412  Q_INVOKABLE static QgsUnitTypes::RenderUnit decodeRenderUnit( const QString &string, bool *ok SIP_OUT = nullptr );
413 
418  static QString toString( QgsUnitTypes::RenderUnit unit );
419 
420 
421  // LAYOUT UNITS
422 
430  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::LayoutUnit unit );
431 
440  Q_INVOKABLE static QgsUnitTypes::LayoutUnit decodeLayoutUnit( const QString &string, bool *ok SIP_OUT = nullptr );
441 
447  Q_INVOKABLE static QgsUnitTypes::LayoutUnitType unitType( QgsUnitTypes::LayoutUnit units );
448 
454  static QString toAbbreviatedString( QgsUnitTypes::LayoutUnit unit );
455 
461  static QString toString( QgsUnitTypes::LayoutUnit unit );
462 
463 };
464 
465 #endif // QGSUNITTYPES_H
Meters value as Map units.
Definition: qgsunittypes.h:119
SystemOfMeasurement
Systems of unit measurement.
Definition: qgsunittypes.h:43
double value
The value part of the distance.
Definition: qgsunittypes.h:174
QgsUnitTypes::DistanceUnit unit
The value part of the distance.
Definition: qgsunittypes.h:160
double value
The value part of the distance.
Definition: qgsunittypes.h:155
Helper functions for various unit types.
Definition: qgsunittypes.h:37
LayoutUnitType
Types of layout units.
Definition: qgsunittypes.h:138
DistanceUnitType
Types of distance units.
Definition: qgsunittypes.h:71
Square millimeters.
Definition: qgsunittypes.h:92
Square kilometers.
Definition: qgsunittypes.h:100
Percentage of another measurement (e.g., canvas size, feature size)
Definition: qgsunittypes.h:115
Typographic points.
Definition: qgsunittypes.h:131
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:183
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:47
AngleUnit
Units of angles.
Definition: qgsunittypes.h:97
points (e.g., for font sizes)
Definition: qgsunittypes.h:117
Degrees, for planar geographic CRS distance measurements.
Definition: qgsunittypes.h:61
International System of Units (SI)
Definition: qgsunittypes.h:46
Square degrees, for planar geographic CRS area measurements.
Definition: qgsunittypes.h:89
A combination of distance value and unit.
Definition: qgsunittypes.h:149
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:53
Unknown distance unit.
Definition: qgsunittypes.h:64
QgsUnitTypes::AreaUnit unit
The value part of the distance.
Definition: qgsunittypes.h:179
Unknown angle unit.
Definition: qgsunittypes.h:105
Unknown unit type.
Definition: qgsunittypes.h:75
Unit is a geographic (e.g., degree based) unit.
Definition: qgsunittypes.h:74
Turn/revolutions.
Definition: qgsunittypes.h:104
#define SIP_OUT
Definition: qgis_sip.h:51
A combination of area value and unit.
Definition: qgsunittypes.h:168
LayoutUnit
Layout measurement units.
Definition: qgsunittypes.h:124
Terrestrial miles.
Definition: qgsunittypes.h:60
AreaUnit
Units of area.
Definition: qgsunittypes.h:79
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:110
Typographic picas.
Definition: qgsunittypes.h:132