QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
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
38class CORE_EXPORT QgsUnitTypes
39{
40 Q_GADGET
41
42 public:
43
49 {
50
54 double value;
55
60 };
61
66 struct AreaValue
67 {
68
72 double value;
73
78 };
79
81 typedef QList<Qgis::RenderUnit> RenderUnitList;
82
89 Q_INVOKABLE static QString encodeUnitType( Qgis::UnitType type );
90
99 Q_INVOKABLE static Qgis::UnitType decodeUnitType( const QString &string, bool *ok SIP_OUT = nullptr );
100
101
102 // DISTANCE UNITS
103
107 Q_INVOKABLE static Qgis::DistanceUnitType unitType( Qgis::DistanceUnit unit );
108
115 Q_INVOKABLE static QString encodeUnit( Qgis::DistanceUnit unit );
116
124 Q_INVOKABLE static Qgis::DistanceUnit decodeDistanceUnit( const QString &string, bool *ok SIP_OUT = nullptr );
125
131 Q_INVOKABLE static QString toString( Qgis::DistanceUnit unit );
132
139 Q_INVOKABLE static QString toAbbreviatedString( Qgis::DistanceUnit unit );
140
148 Q_INVOKABLE static Qgis::DistanceUnit stringToDistanceUnit( const QString &string, bool *ok SIP_OUT = nullptr );
149
156 Q_INVOKABLE static double fromUnitToUnitFactor( Qgis::DistanceUnit fromUnit, Qgis::DistanceUnit toUnit );
157
158 // AREAL UNITS
159
163 static Qgis::DistanceUnitType unitType( Qgis::AreaUnit unit );
164
171 static QString encodeUnit( Qgis::AreaUnit unit );
172
180 Q_INVOKABLE static Qgis::AreaUnit decodeAreaUnit( const QString &string, bool *ok SIP_OUT = nullptr );
181
187 static QString toString( Qgis::AreaUnit unit );
188
195 static QString toAbbreviatedString( Qgis::AreaUnit unit );
196
204 Q_INVOKABLE static Qgis::AreaUnit stringToAreaUnit( const QString &string, bool *ok SIP_OUT = nullptr );
205
212 static double fromUnitToUnitFactor( Qgis::AreaUnit fromUnit, Qgis::AreaUnit toUnit );
213
219 Q_INVOKABLE static Qgis::AreaUnit distanceToAreaUnit( Qgis::DistanceUnit distanceUnit );
220
227 Q_INVOKABLE static Qgis::DistanceUnit areaToDistanceUnit( Qgis::AreaUnit areaUnit );
228
229 // TEMPORAL UNITS
230
237 static QString encodeUnit( Qgis::TemporalUnit unit );
238
247 Q_INVOKABLE static Qgis::TemporalUnit decodeTemporalUnit( const QString &string, bool *ok SIP_OUT = nullptr );
248
254 static QString toString( Qgis::TemporalUnit unit );
255
262 static QString toAbbreviatedString( Qgis::TemporalUnit unit );
263
272 Q_INVOKABLE static Qgis::TemporalUnit stringToTemporalUnit( const QString &string, bool *ok SIP_OUT = nullptr );
273
285 static double fromUnitToUnitFactor( Qgis::TemporalUnit fromUnit, Qgis::TemporalUnit toUnit );
286
287 // VOLUME UNITS
288
293 static Qgis::DistanceUnitType unitType( Qgis::VolumeUnit unit );
294
301 static QString encodeUnit( Qgis::VolumeUnit unit );
302
311 Q_INVOKABLE static Qgis::VolumeUnit decodeVolumeUnit( const QString &string, bool *ok SIP_OUT = nullptr );
312
318 static QString toString( Qgis::VolumeUnit unit );
319
326 static QString toAbbreviatedString( Qgis::VolumeUnit unit );
327
336 Q_INVOKABLE static Qgis::VolumeUnit stringToVolumeUnit( const QString &string, bool *ok SIP_OUT = nullptr );
337
345 static double fromUnitToUnitFactor( Qgis::VolumeUnit fromUnit, Qgis::VolumeUnit toUnit );
346
353 Q_INVOKABLE static Qgis::VolumeUnit distanceToVolumeUnit( Qgis::DistanceUnit distanceUnit );
354
361 Q_INVOKABLE static Qgis::DistanceUnit volumeToDistanceUnit( Qgis::VolumeUnit volumeUnit );
362
363 // ANGULAR UNITS
364
371 static QString encodeUnit( Qgis::AngleUnit unit );
372
380 Q_INVOKABLE static Qgis::AngleUnit decodeAngleUnit( const QString &string, bool *ok SIP_OUT = nullptr );
381
386 static QString toString( Qgis::AngleUnit unit );
387
394 static double fromUnitToUnitFactor( Qgis::AngleUnit fromUnit, Qgis::AngleUnit toUnit );
395
403 Q_INVOKABLE static QString formatAngle( double angle, int decimals, Qgis::AngleUnit unit );
404
413 Q_INVOKABLE static QgsUnitTypes::DistanceValue scaledDistance( double distance, Qgis::DistanceUnit unit, int decimals, bool keepBaseUnit = false );
414
423 Q_INVOKABLE static QgsUnitTypes::AreaValue scaledArea( double area, Qgis::AreaUnit unit, int decimals, bool keepBaseUnit = false );
424
435 Q_INVOKABLE static QString formatDistance( double distance, int decimals, Qgis::DistanceUnit unit, bool keepBaseUnit = false );
436
447 Q_INVOKABLE static QString formatArea( double area, int decimals, Qgis::AreaUnit unit, bool keepBaseUnit = false );
448
449 // RENDER UNITS
450
457 static QString encodeUnit( Qgis::RenderUnit unit );
458
466 Q_INVOKABLE static Qgis::RenderUnit decodeRenderUnit( const QString &string, bool *ok SIP_OUT = nullptr );
467
468
472 static QString toString( Qgis::RenderUnit unit );
473
480 static QString toAbbreviatedString( Qgis::RenderUnit unit );
481
482
483 // LAYOUT UNITS
484
491 static QString encodeUnit( Qgis::LayoutUnit unit );
492
500 Q_INVOKABLE static Qgis::LayoutUnit decodeLayoutUnit( const QString &string, bool *ok SIP_OUT = nullptr );
501
506 Q_INVOKABLE static Qgis::LayoutUnitType unitType( Qgis::LayoutUnit units );
507
512 static QString toAbbreviatedString( Qgis::LayoutUnit unit );
513
518 static QString toString( Qgis::LayoutUnit unit );
519
520};
521
522#endif // QGSUNITTYPES_H
DistanceUnitType
Types of distance units.
Definition qgis.h:4731
UnitType
Unit types.
Definition qgis.h:4652
LayoutUnit
Layout measurement units.
Definition qgis.h:4859
AngleUnit
Units of angles.
Definition qgis.h:4794
DistanceUnit
Units of distance.
Definition qgis.h:4669
AreaUnit
Units of area.
Definition qgis.h:4746
TemporalUnit
Temporal units.
Definition qgis.h:4815
RenderUnit
Rendering size units.
Definition qgis.h:4839
LayoutUnitType
Types of layout units.
Definition qgis.h:4879
VolumeUnit
Units of volume.
Definition qgis.h:4771
Helper functions for various unit types.
QList< Qgis::RenderUnit > RenderUnitList
List of render units.
#define SIP_OUT
Definition qgis_sip.h:58
A combination of area value and unit.
double value
The value part of the distance.
Qgis::AreaUnit unit
The value part of the distance.
A combination of distance value and unit.
double value
The value part of the distance.
Qgis::DistanceUnit unit
The value part of the distance.