QGIS API Documentation  3.9.0-Master (224899f119)
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,
109  };
110  Q_ENUM( AngleUnit )
111 
112 
114  {
115  RenderMillimeters = 0,
123  };
124  Q_ENUM( RenderUnit )
125 
126 
128  {
129  LayoutMillimeters = 0,
136  LayoutPixels
137  };
138  Q_ENUM( LayoutUnit )
139 
140 
142  {
143  LayoutPaperUnits = 0,
144  LayoutScreenUnits
145  };
146 
153  {
154 
158  double value;
159 
164  };
165 
171  struct AreaValue
172  {
173 
177  double value;
178 
183  };
184 
186  typedef QList<QgsUnitTypes::RenderUnit> RenderUnitList;
187 
188  // DISTANCE UNITS
189 
193  Q_INVOKABLE static DistanceUnitType unitType( QgsUnitTypes::DistanceUnit unit );
194 
201  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::DistanceUnit unit );
202 
210  Q_INVOKABLE static QgsUnitTypes::DistanceUnit decodeDistanceUnit( const QString &string, bool *ok SIP_OUT = nullptr );
211 
217  Q_INVOKABLE static QString toString( QgsUnitTypes::DistanceUnit unit );
218 
226  Q_INVOKABLE static QString toAbbreviatedString( QgsUnitTypes::DistanceUnit unit );
227 
235  Q_INVOKABLE static QgsUnitTypes::DistanceUnit stringToDistanceUnit( const QString &string, bool *ok SIP_OUT = nullptr );
236 
243  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit );
244 
245  // AREAL UNITS
246 
250  Q_INVOKABLE static DistanceUnitType unitType( QgsUnitTypes::AreaUnit unit );
251 
258  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::AreaUnit unit );
259 
267  Q_INVOKABLE static AreaUnit decodeAreaUnit( const QString &string, bool *ok SIP_OUT = nullptr );
268 
274  static QString toString( QgsUnitTypes::AreaUnit unit );
275 
283  static QString toAbbreviatedString( QgsUnitTypes::AreaUnit unit );
284 
292  Q_INVOKABLE static AreaUnit stringToAreaUnit( const QString &string, bool *ok SIP_OUT = nullptr );
293 
300  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::AreaUnit fromUnit, QgsUnitTypes::AreaUnit toUnit );
301 
307  Q_INVOKABLE static QgsUnitTypes::AreaUnit distanceToAreaUnit( QgsUnitTypes::DistanceUnit distanceUnit );
308 
315  Q_INVOKABLE static QgsUnitTypes::DistanceUnit areaToDistanceUnit( QgsUnitTypes::AreaUnit areaUnit );
316 
317  // ANGULAR UNITS
318 
325  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::AngleUnit unit );
326 
334  Q_INVOKABLE static QgsUnitTypes::AngleUnit decodeAngleUnit( const QString &string, bool *ok SIP_OUT = nullptr );
335 
340  static QString toString( QgsUnitTypes::AngleUnit unit );
341 
348  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::AngleUnit fromUnit, QgsUnitTypes::AngleUnit toUnit );
349 
357  Q_INVOKABLE static QString formatAngle( double angle, int decimals, QgsUnitTypes::AngleUnit unit );
358 
359 
369  Q_INVOKABLE static QgsUnitTypes::DistanceValue scaledDistance( double distance, QgsUnitTypes::DistanceUnit unit, int decimals, bool keepBaseUnit = false );
370 
380  Q_INVOKABLE static QgsUnitTypes::AreaValue scaledArea( double area, QgsUnitTypes::AreaUnit unit, int decimals, bool keepBaseUnit = false );
381 
393  Q_INVOKABLE static QString formatDistance( double distance, int decimals, QgsUnitTypes::DistanceUnit unit, bool keepBaseUnit = false );
394 
406  Q_INVOKABLE static QString formatArea( double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit = false );
407 
408  // RENDER UNITS
409 
416  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::RenderUnit unit );
417 
425  Q_INVOKABLE static QgsUnitTypes::RenderUnit decodeRenderUnit( const QString &string, bool *ok SIP_OUT = nullptr );
426 
427 
432  static QString toString( QgsUnitTypes::RenderUnit unit );
433 
440  Q_INVOKABLE static QString toAbbreviatedString( QgsUnitTypes::RenderUnit unit );
441 
442 
443  // LAYOUT UNITS
444 
452  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::LayoutUnit unit );
453 
462  Q_INVOKABLE static QgsUnitTypes::LayoutUnit decodeLayoutUnit( const QString &string, bool *ok SIP_OUT = nullptr );
463 
469  Q_INVOKABLE static QgsUnitTypes::LayoutUnitType unitType( QgsUnitTypes::LayoutUnit units );
470 
476  static QString toAbbreviatedString( QgsUnitTypes::LayoutUnit unit );
477 
483  static QString toString( QgsUnitTypes::LayoutUnit unit );
484 
485 };
486 
487 #endif // QGSUNITTYPES_H
Meters value as Map units.
Definition: qgsunittypes.h:122
SystemOfMeasurement
Systems of unit measurement.
Definition: qgsunittypes.h:44
double value
The value part of the distance.
Definition: qgsunittypes.h:177
QgsUnitTypes::DistanceUnit unit
The value part of the distance.
Definition: qgsunittypes.h:163
double value
The value part of the distance.
Definition: qgsunittypes.h:158
Helper functions for various unit types.
Definition: qgsunittypes.h:38
LayoutUnitType
Types of layout units.
Definition: qgsunittypes.h:141
DistanceUnitType
Types of distance units.
Definition: qgsunittypes.h:72
Unknown areal unit.
Definition: qgsunittypes.h:93
Mixed or unknown units.
Definition: qgsunittypes.h:121
Square kilometers.
Definition: qgsunittypes.h:101
Percentage of another measurement (e.g., canvas size, feature size)
Definition: qgsunittypes.h:118
Typographic points.
Definition: qgsunittypes.h:134
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:186
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
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:152
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:182
Unknown angle unit.
Definition: qgsunittypes.h:108
Unknown unit type.
Definition: qgsunittypes.h:76
Unit is a geographic (e.g., degree based) unit.
Definition: qgsunittypes.h:75
Points (e.g., for font sizes)
Definition: qgsunittypes.h:119
Turn/revolutions.
Definition: qgsunittypes.h:105
#define SIP_OUT
Definition: qgis_sip.h:58
A combination of area value and unit.
Definition: qgsunittypes.h:171
LayoutUnit
Layout measurement units.
Definition: qgsunittypes.h:127
Angular milliradians (SI definition, 1/1000 of radian)
Definition: qgsunittypes.h:106
Angular mil (NATO definition, 6400 mil = 2PI radians)
Definition: qgsunittypes.h:107
Terrestrial miles.
Definition: qgsunittypes.h:61
AreaUnit
Units of area.
Definition: qgsunittypes.h:80
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:113
Typographic picas.
Definition: qgsunittypes.h:135