QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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 "qgis.h"
24#include <QObject>
25
26/***************************************************************************
27 * This class is considered CRITICAL and any change MUST be accompanied with
28 * full unit tests in test_qgsunittypes.py.
29 * See details in QEP #17
30 ****************************************************************************/
31
39class CORE_EXPORT QgsUnitTypes
40{
41 Q_GADGET
42
43 public:
44
51 {
52
56 double value;
57
62 };
63
69 struct AreaValue
70 {
71
75 double value;
76
81 };
82
84 typedef QList<Qgis::RenderUnit> RenderUnitList;
85
92 Q_INVOKABLE static QString encodeUnitType( Qgis::UnitType type );
93
102 Q_INVOKABLE static Qgis::UnitType decodeUnitType( const QString &string, bool *ok SIP_OUT = nullptr );
103
104
105 // DISTANCE UNITS
106
110 Q_INVOKABLE static Qgis::DistanceUnitType unitType( Qgis::DistanceUnit unit );
111
118 Q_INVOKABLE static QString encodeUnit( Qgis::DistanceUnit unit );
119
127 Q_INVOKABLE static Qgis::DistanceUnit decodeDistanceUnit( const QString &string, bool *ok SIP_OUT = nullptr );
128
134 Q_INVOKABLE static QString toString( Qgis::DistanceUnit unit );
135
143 Q_INVOKABLE static QString toAbbreviatedString( Qgis::DistanceUnit unit );
144
152 Q_INVOKABLE static Qgis::DistanceUnit stringToDistanceUnit( const QString &string, bool *ok SIP_OUT = nullptr );
153
160 Q_INVOKABLE static double fromUnitToUnitFactor( Qgis::DistanceUnit fromUnit, Qgis::DistanceUnit toUnit );
161
162 // AREAL UNITS
163
167 static Qgis::DistanceUnitType unitType( Qgis::AreaUnit unit );
168
175 static QString encodeUnit( Qgis::AreaUnit unit );
176
184 Q_INVOKABLE static Qgis::AreaUnit decodeAreaUnit( const QString &string, bool *ok SIP_OUT = nullptr );
185
191 static QString toString( Qgis::AreaUnit unit );
192
200 static QString toAbbreviatedString( Qgis::AreaUnit unit );
201
209 Q_INVOKABLE static Qgis::AreaUnit stringToAreaUnit( const QString &string, bool *ok SIP_OUT = nullptr );
210
217 static double fromUnitToUnitFactor( Qgis::AreaUnit fromUnit, Qgis::AreaUnit toUnit );
218
224 Q_INVOKABLE static Qgis::AreaUnit distanceToAreaUnit( Qgis::DistanceUnit distanceUnit );
225
232 Q_INVOKABLE static Qgis::DistanceUnit areaToDistanceUnit( Qgis::AreaUnit areaUnit );
233
234 // TEMPORAL UNITS
235
242 static QString encodeUnit( Qgis::TemporalUnit unit );
243
252 Q_INVOKABLE static Qgis::TemporalUnit decodeTemporalUnit( const QString &string, bool *ok SIP_OUT = nullptr );
253
259 static QString toString( Qgis::TemporalUnit unit );
260
267 static QString toAbbreviatedString( Qgis::TemporalUnit unit );
268
277 Q_INVOKABLE static Qgis::TemporalUnit stringToTemporalUnit( const QString &string, bool *ok SIP_OUT = nullptr );
278
290 static double fromUnitToUnitFactor( Qgis::TemporalUnit fromUnit, Qgis::TemporalUnit toUnit );
291
292 // VOLUME UNITS
293
298 static Qgis::DistanceUnitType unitType( Qgis::VolumeUnit unit );
299
306 static QString encodeUnit( Qgis::VolumeUnit unit );
307
316 Q_INVOKABLE static Qgis::VolumeUnit decodeVolumeUnit( const QString &string, bool *ok SIP_OUT = nullptr );
317
323 static QString toString( Qgis::VolumeUnit unit );
324
331 static QString toAbbreviatedString( Qgis::VolumeUnit unit );
332
341 Q_INVOKABLE static Qgis::VolumeUnit stringToVolumeUnit( const QString &string, bool *ok SIP_OUT = nullptr );
342
350 static double fromUnitToUnitFactor( Qgis::VolumeUnit fromUnit, Qgis::VolumeUnit toUnit );
351
358 Q_INVOKABLE static Qgis::VolumeUnit distanceToVolumeUnit( Qgis::DistanceUnit distanceUnit );
359
366 Q_INVOKABLE static Qgis::DistanceUnit volumeToDistanceUnit( Qgis::VolumeUnit volumeUnit );
367
368 // ANGULAR UNITS
369
376 static QString encodeUnit( Qgis::AngleUnit unit );
377
385 Q_INVOKABLE static Qgis::AngleUnit decodeAngleUnit( const QString &string, bool *ok SIP_OUT = nullptr );
386
391 static QString toString( Qgis::AngleUnit unit );
392
399 static double fromUnitToUnitFactor( Qgis::AngleUnit fromUnit, Qgis::AngleUnit toUnit );
400
408 Q_INVOKABLE static QString formatAngle( double angle, int decimals, Qgis::AngleUnit unit );
409
419 Q_INVOKABLE static QgsUnitTypes::DistanceValue scaledDistance( double distance, Qgis::DistanceUnit unit, int decimals, bool keepBaseUnit = false );
420
430 Q_INVOKABLE static QgsUnitTypes::AreaValue scaledArea( double area, Qgis::AreaUnit unit, int decimals, bool keepBaseUnit = false );
431
443 Q_INVOKABLE static QString formatDistance( double distance, int decimals, Qgis::DistanceUnit unit, bool keepBaseUnit = false );
444
456 Q_INVOKABLE static QString formatArea( double area, int decimals, Qgis::AreaUnit unit, bool keepBaseUnit = false );
457
458 // RENDER UNITS
459
466 static QString encodeUnit( Qgis::RenderUnit unit );
467
475 Q_INVOKABLE static Qgis::RenderUnit decodeRenderUnit( const QString &string, bool *ok SIP_OUT = nullptr );
476
477
482 static QString toString( Qgis::RenderUnit unit );
483
490 static QString toAbbreviatedString( Qgis::RenderUnit unit );
491
492
493 // LAYOUT UNITS
494
502 static QString encodeUnit( Qgis::LayoutUnit unit );
503
512 Q_INVOKABLE static Qgis::LayoutUnit decodeLayoutUnit( const QString &string, bool *ok SIP_OUT = nullptr );
513
519 Q_INVOKABLE static Qgis::LayoutUnitType unitType( Qgis::LayoutUnit units );
520
526 static QString toAbbreviatedString( Qgis::LayoutUnit unit );
527
533 static QString toString( Qgis::LayoutUnit unit );
534
535};
536
537#endif // QGSUNITTYPES_H
DistanceUnitType
Types of distance units.
Definition: qgis.h:3069
UnitType
Unit types.
Definition: qgis.h:3030
LayoutUnit
Layout measurement units.
Definition: qgis.h:3196
AngleUnit
Units of angles.
Definition: qgis.h:3131
DistanceUnit
Units of distance.
Definition: qgis.h:3047
AreaUnit
Units of area.
Definition: qgis.h:3084
TemporalUnit
Temporal units.
Definition: qgis.h:3152
RenderUnit
Rendering size units.
Definition: qgis.h:3176
LayoutUnitType
Types of layout units.
Definition: qgis.h:3216
VolumeUnit
Units of volume.
Definition: qgis.h:3108
Helper functions for various unit types.
Definition: qgsunittypes.h:40
QList< Qgis::RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:84
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
#define SIP_OUT
Definition: qgis_sip.h:58
A combination of area value and unit.
Definition: qgsunittypes.h:70
double value
The value part of the distance.
Definition: qgsunittypes.h:75
Qgis::AreaUnit unit
The value part of the distance.
Definition: qgsunittypes.h:80
A combination of distance value and unit.
Definition: qgsunittypes.h:51
double value
The value part of the distance.
Definition: qgsunittypes.h:56
Qgis::DistanceUnit unit
The value part of the distance.
Definition: qgsunittypes.h:61