QGIS API Documentation  3.6.0-Noosa (5873452)
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 
55  {
56  DistanceMeters = 0,
66  };
67  Q_ENUM( DistanceUnit )
68 
69 
73  {
74  Standard = 0,
77  };
78 
80  enum AreaUnit
81  {
82  AreaSquareMeters = 0,
94  };
95  Q_ENUM( AreaUnit )
96 
97 
98  enum AngleUnit
99  {
100  AngleDegrees = 0,
107  };
108  Q_ENUM( AngleUnit )
109 
110 
112  {
113  RenderMillimeters = 0,
121  };
122  Q_ENUM( RenderUnit )
123 
124 
126  {
127  LayoutMillimeters = 0,
134  LayoutPixels
135  };
136  Q_ENUM( LayoutUnit )
137 
138 
140  {
141  LayoutPaperUnits = 0,
142  LayoutScreenUnits
143  };
144 
151  {
152 
156  double value;
157 
162  };
163 
169  struct AreaValue
170  {
171 
175  double value;
176 
181  };
182 
184  typedef QList<QgsUnitTypes::RenderUnit> RenderUnitList;
185 
186  // DISTANCE UNITS
187 
191  Q_INVOKABLE static DistanceUnitType unitType( QgsUnitTypes::DistanceUnit unit );
192 
199  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::DistanceUnit unit );
200 
208  Q_INVOKABLE static QgsUnitTypes::DistanceUnit decodeDistanceUnit( const QString &string, bool *ok SIP_OUT = nullptr );
209 
215  Q_INVOKABLE static QString toString( QgsUnitTypes::DistanceUnit unit );
216 
224  Q_INVOKABLE static QString toAbbreviatedString( QgsUnitTypes::DistanceUnit unit );
225 
233  Q_INVOKABLE static QgsUnitTypes::DistanceUnit stringToDistanceUnit( const QString &string, bool *ok SIP_OUT = nullptr );
234 
241  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit );
242 
243  // AREAL UNITS
244 
248  Q_INVOKABLE static DistanceUnitType unitType( QgsUnitTypes::AreaUnit unit );
249 
256  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::AreaUnit unit );
257 
265  Q_INVOKABLE static AreaUnit decodeAreaUnit( const QString &string, bool *ok SIP_OUT = nullptr );
266 
272  static QString toString( QgsUnitTypes::AreaUnit unit );
273 
281  static QString toAbbreviatedString( QgsUnitTypes::AreaUnit unit );
282 
290  Q_INVOKABLE static AreaUnit stringToAreaUnit( const QString &string, bool *ok SIP_OUT = nullptr );
291 
298  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::AreaUnit fromUnit, QgsUnitTypes::AreaUnit toUnit );
299 
305  Q_INVOKABLE static QgsUnitTypes::AreaUnit distanceToAreaUnit( QgsUnitTypes::DistanceUnit distanceUnit );
306 
307  // ANGULAR UNITS
308 
315  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::AngleUnit unit );
316 
324  Q_INVOKABLE static QgsUnitTypes::AngleUnit decodeAngleUnit( const QString &string, bool *ok SIP_OUT = nullptr );
325 
330  static QString toString( QgsUnitTypes::AngleUnit unit );
331 
338  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::AngleUnit fromUnit, QgsUnitTypes::AngleUnit toUnit );
339 
347  Q_INVOKABLE static QString formatAngle( double angle, int decimals, QgsUnitTypes::AngleUnit unit );
348 
349 
359  Q_INVOKABLE static QgsUnitTypes::DistanceValue scaledDistance( double distance, QgsUnitTypes::DistanceUnit unit, int decimals, bool keepBaseUnit = false );
360 
370  Q_INVOKABLE static QgsUnitTypes::AreaValue scaledArea( double area, QgsUnitTypes::AreaUnit unit, int decimals, bool keepBaseUnit = false );
371 
383  Q_INVOKABLE static QString formatDistance( double distance, int decimals, QgsUnitTypes::DistanceUnit unit, bool keepBaseUnit = false );
384 
396  Q_INVOKABLE static QString formatArea( double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit = false );
397 
398  // RENDER UNITS
399 
406  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::RenderUnit unit );
407 
415  Q_INVOKABLE static QgsUnitTypes::RenderUnit decodeRenderUnit( const QString &string, bool *ok SIP_OUT = nullptr );
416 
421  static QString toString( QgsUnitTypes::RenderUnit unit );
422 
423 
424  // LAYOUT UNITS
425 
433  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::LayoutUnit unit );
434 
443  Q_INVOKABLE static QgsUnitTypes::LayoutUnit decodeLayoutUnit( const QString &string, bool *ok SIP_OUT = nullptr );
444 
450  Q_INVOKABLE static QgsUnitTypes::LayoutUnitType unitType( QgsUnitTypes::LayoutUnit units );
451 
457  static QString toAbbreviatedString( QgsUnitTypes::LayoutUnit unit );
458 
464  static QString toString( QgsUnitTypes::LayoutUnit unit );
465 
466 };
467 
468 #endif // QGSUNITTYPES_H
Meters value as Map units.
Definition: qgsunittypes.h:120
SystemOfMeasurement
Systems of unit measurement.
Definition: qgsunittypes.h:44
double value
The value part of the distance.
Definition: qgsunittypes.h:175
QgsUnitTypes::DistanceUnit unit
The value part of the distance.
Definition: qgsunittypes.h:161
double value
The value part of the distance.
Definition: qgsunittypes.h:156
Helper functions for various unit types.
Definition: qgsunittypes.h:38
LayoutUnitType
Types of layout units.
Definition: qgsunittypes.h:139
DistanceUnitType
Types of distance units.
Definition: qgsunittypes.h:72
Square millimeters.
Definition: qgsunittypes.h:93
Square kilometers.
Definition: qgsunittypes.h:101
Percentage of another measurement (e.g., canvas size, feature size)
Definition: qgsunittypes.h:116
Typographic points.
Definition: qgsunittypes.h:132
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:184
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:98
points (e.g., for font sizes)
Definition: qgsunittypes.h:118
Degrees, for planar geographic CRS distance measurements.
Definition: qgsunittypes.h:62
International System of Units (SI)
Definition: qgsunittypes.h:47
Square degrees, for planar geographic CRS area measurements.
Definition: qgsunittypes.h:90
A combination of distance value and unit.
Definition: qgsunittypes.h:150
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:54
Unknown distance unit.
Definition: qgsunittypes.h:65
QgsUnitTypes::AreaUnit unit
The value part of the distance.
Definition: qgsunittypes.h:180
Unknown angle unit.
Definition: qgsunittypes.h:106
Unknown unit type.
Definition: qgsunittypes.h:76
Unit is a geographic (e.g., degree based) unit.
Definition: qgsunittypes.h:75
Turn/revolutions.
Definition: qgsunittypes.h:105
#define SIP_OUT
Definition: qgis_sip.h:51
A combination of area value and unit.
Definition: qgsunittypes.h:169
LayoutUnit
Layout measurement units.
Definition: qgsunittypes.h:125
Terrestrial miles.
Definition: qgsunittypes.h:61
AreaUnit
Units of area.
Definition: qgsunittypes.h:80
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:111
Typographic picas.
Definition: qgsunittypes.h:133