QGIS API Documentation  3.0.2-Girona (307d082)
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  DistanceMeters = 0,
55  };
56  Q_ENUM( DistanceUnit );
57 
62  {
63  Standard = 0,
66  };
67 
69  enum AreaUnit
70  {
71  AreaSquareMeters = 0,
83  };
84  Q_ENUM( AreaUnit );
85 
87  enum AngleUnit
88  {
89  AngleDegrees = 0,
96  };
97  Q_ENUM( AngleUnit );
98 
101  {
102  RenderMillimeters = 0,
110  };
111  Q_ENUM( RenderUnit );
112 
115  {
116  LayoutMillimeters = 0,
123  LayoutPixels
124  };
125  Q_ENUM( LayoutUnit );
126 
129  {
130  LayoutPaperUnits = 0,
131  LayoutScreenUnits
132  };
133 
140  {
141 
145  double value;
146 
151  };
152 
158  struct AreaValue
159  {
160 
164  double value;
165 
170  };
171 
173  typedef QList<QgsUnitTypes::RenderUnit> RenderUnitList;
174 
175  // DISTANCE UNITS
176 
180  Q_INVOKABLE static DistanceUnitType unitType( QgsUnitTypes::DistanceUnit unit );
181 
188  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::DistanceUnit unit );
189 
197  Q_INVOKABLE static QgsUnitTypes::DistanceUnit decodeDistanceUnit( const QString &string, bool *ok SIP_OUT = nullptr );
198 
204  Q_INVOKABLE static QString toString( QgsUnitTypes::DistanceUnit unit );
205 
213  Q_INVOKABLE static QString toAbbreviatedString( QgsUnitTypes::DistanceUnit unit );
214 
221  Q_INVOKABLE static QgsUnitTypes::DistanceUnit stringToDistanceUnit( const QString &string, bool *ok SIP_OUT = nullptr );
222 
229  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit );
230 
231  // AREAL UNITS
232 
236  Q_INVOKABLE static DistanceUnitType unitType( QgsUnitTypes::AreaUnit unit );
237 
244  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::AreaUnit unit );
245 
253  Q_INVOKABLE static AreaUnit decodeAreaUnit( const QString &string, bool *ok SIP_OUT = nullptr );
254 
260  Q_INVOKABLE static QString toString( QgsUnitTypes::AreaUnit unit );
261 
269  Q_INVOKABLE static QString toAbbreviatedString( QgsUnitTypes::AreaUnit unit );
270 
277  Q_INVOKABLE static AreaUnit stringToAreaUnit( const QString &string, bool *ok SIP_OUT = nullptr );
278 
285  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::AreaUnit fromUnit, QgsUnitTypes::AreaUnit toUnit );
286 
292  Q_INVOKABLE static QgsUnitTypes::AreaUnit distanceToAreaUnit( QgsUnitTypes::DistanceUnit distanceUnit );
293 
294  // ANGULAR UNITS
295 
302  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::AngleUnit unit );
303 
311  Q_INVOKABLE static QgsUnitTypes::AngleUnit decodeAngleUnit( const QString &string, bool *ok SIP_OUT = nullptr );
312 
317  Q_INVOKABLE static QString toString( QgsUnitTypes::AngleUnit unit );
318 
325  Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::AngleUnit fromUnit, QgsUnitTypes::AngleUnit toUnit );
326 
334  Q_INVOKABLE static QString formatAngle( double angle, int decimals, QgsUnitTypes::AngleUnit unit );
335 
336 
346  Q_INVOKABLE static QgsUnitTypes::DistanceValue scaledDistance( double distance, QgsUnitTypes::DistanceUnit unit, int decimals, bool keepBaseUnit = false );
347 
357  Q_INVOKABLE static QgsUnitTypes::AreaValue scaledArea( double area, QgsUnitTypes::AreaUnit unit, int decimals, bool keepBaseUnit = false );
358 
370  Q_INVOKABLE static QString formatDistance( double distance, int decimals, QgsUnitTypes::DistanceUnit unit, bool keepBaseUnit = false );
371 
383  Q_INVOKABLE static QString formatArea( double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit = false );
384 
385  // RENDER UNITS
386 
393  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::RenderUnit unit );
394 
402  Q_INVOKABLE static QgsUnitTypes::RenderUnit decodeRenderUnit( const QString &string, bool *ok SIP_OUT = nullptr );
403 
408  Q_INVOKABLE static QString toString( QgsUnitTypes::RenderUnit unit );
409 
410 
411  // LAYOUT UNITS
412 
420  Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::LayoutUnit unit );
421 
430  Q_INVOKABLE static QgsUnitTypes::LayoutUnit decodeLayoutUnit( const QString &string, bool *ok SIP_OUT = nullptr );
431 
437  Q_INVOKABLE static QgsUnitTypes::LayoutUnitType unitType( const QgsUnitTypes::LayoutUnit units );
438 
444  Q_INVOKABLE static QString toAbbreviatedString( QgsUnitTypes::LayoutUnit unit );
445 
451  Q_INVOKABLE static QString toString( QgsUnitTypes::LayoutUnit unit );
452 
453 };
454 
455 #endif // QGSUNITTYPES_H
Meters value as Map units.
Definition: qgsunittypes.h:109
double value
The value part of the distance.
Definition: qgsunittypes.h:164
QgsUnitTypes::DistanceUnit unit
The value part of the distance.
Definition: qgsunittypes.h:150
double value
The value part of the distance.
Definition: qgsunittypes.h:145
Helper functions for various unit types.
Definition: qgsunittypes.h:37
LayoutUnitType
Types of layout units.
Definition: qgsunittypes.h:128
DistanceUnitType
Types of distance units.
Definition: qgsunittypes.h:61
Square millimeters.
Definition: qgsunittypes.h:82
Square kilometers.
Definition: qgsunittypes.h:90
Percentage of another measurement (e.g., canvas size, feature size)
Definition: qgsunittypes.h:105
Typographic points.
Definition: qgsunittypes.h:121
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:173
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
AngleUnit
Units of angles.
Definition: qgsunittypes.h:87
points (e.g., for font sizes)
Definition: qgsunittypes.h:107
Degrees, for planar geographic CRS distance measurements.
Definition: qgsunittypes.h:51
Square degrees, for planar geographic CRS area measurements.
Definition: qgsunittypes.h:79
A combination of distance value and unit.
Definition: qgsunittypes.h:139
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:43
Unknown distance unit.
Definition: qgsunittypes.h:54
QgsUnitTypes::AreaUnit unit
The value part of the distance.
Definition: qgsunittypes.h:169
Unknown angle unit.
Definition: qgsunittypes.h:95
Unknown unit type.
Definition: qgsunittypes.h:65
Unit is a geographic (e.g., degree based) unit.
Definition: qgsunittypes.h:64
Turn/revolutions.
Definition: qgsunittypes.h:94
#define SIP_OUT
Definition: qgis_sip.h:51
A combination of area value and unit.
Definition: qgsunittypes.h:158
LayoutUnit
Layout measurement units.
Definition: qgsunittypes.h:114
Terrestrial miles.
Definition: qgsunittypes.h:50
AreaUnit
Units of area.
Definition: qgsunittypes.h:69
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:100
Typographic picas.
Definition: qgsunittypes.h:122