Skip to content
Permalink
Browse files

Expose QgsUnitTypes to QML

  • Loading branch information
m-kuhn committed Oct 20, 2016
1 parent 58be4fc commit 3e83fafc42212d35f9fa26a2469e7cdb9688adfc
Showing with 23 additions and 21 deletions.
  1. +1 −1 src/core/CMakeLists.txt
  2. +22 −20 src/core/qgsunittypes.h
@@ -488,6 +488,7 @@ SET(QGIS_CORE_MOC_HDRS
qgstracer.h
qgstransaction.h
qgstransactiongroup.h
qgsunittypes.h
qgsvectordataprovider.h
qgsvectorlayercache.h
qgsvectorlayereditbuffer.h
@@ -705,7 +706,6 @@ SET(QGIS_CORE_HDRS
qgstextlabelfeature.h
qgstolerance.h
qgstracer.h
qgsunittypes.h

qgsvectordataprovider.h
qgsvectorlayercache.h
@@ -34,6 +34,8 @@

class CORE_EXPORT QgsUnitTypes
{
Q_GADGET

public:

//! Units of distance
@@ -102,89 +104,89 @@ class CORE_EXPORT QgsUnitTypes

/** Returns the type for a distance unit.
*/
static DistanceUnitType unitType( DistanceUnit unit );
Q_INVOKABLE static DistanceUnitType unitType( DistanceUnit unit );

/** Encodes a distance unit to a string.
* @param unit unit to encode
* @returns encoded string
* @see decodeDistanceUnit()
*/
static QString encodeUnit( QgsUnitTypes::DistanceUnit unit );
Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::DistanceUnit unit );

/** Decodes a distance unit from a string.
* @param string string to decode
* @param ok optional boolean, will be set to true if string was converted successfully
* @returns decoded units
* @see encodeUnit()
*/
static QgsUnitTypes::DistanceUnit decodeDistanceUnit( const QString& string, bool *ok = 0 );
Q_INVOKABLE static QgsUnitTypes::DistanceUnit decodeDistanceUnit( const QString& string, bool *ok = 0 );

/** Returns a translated string representing a distance unit.
* @param unit unit to convert to string
* @see stringToDistanceUnit()
*/
static QString toString( QgsUnitTypes::DistanceUnit unit );
Q_INVOKABLE static QString toString( QgsUnitTypes::DistanceUnit unit );

/** Converts a translated string to a distance unit.
* @param string string representing a distance unit
* @param ok optional boolean, will be set to true if string was converted successfully
* @see toString()
*/
static QgsUnitTypes::DistanceUnit stringToDistanceUnit( const QString& string, bool *ok = 0 );
Q_INVOKABLE static QgsUnitTypes::DistanceUnit stringToDistanceUnit( const QString& string, bool *ok = 0 );

/** Returns the conversion factor between the specified distance units.
* @param fromUnit distance unit to convert from
* @param toUnit distance unit to convert to
* @returns multiplication factor to convert between units
*/
static double fromUnitToUnitFactor( QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit );
Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit );

// AREAL UNITS

/** Returns the type for an areal unit.
*/
static DistanceUnitType unitType( AreaUnit unit );
Q_INVOKABLE static DistanceUnitType unitType( AreaUnit unit );

/** Encodes an areal unit to a string.
* @param unit unit to encode
* @returns encoded string
* @see decodeAreaUnit()
*/
static QString encodeUnit( AreaUnit unit );
Q_INVOKABLE static QString encodeUnit( AreaUnit unit );

/** Decodes an areal unit from a string.
* @param string string to decode
* @param ok optional boolean, will be set to true if string was converted successfully
* @returns decoded units
* @see encodeUnit()
*/
static AreaUnit decodeAreaUnit( const QString& string, bool *ok = 0 );
Q_INVOKABLE static AreaUnit decodeAreaUnit( const QString& string, bool *ok = 0 );

/** Returns a translated string representing an areal unit.
* @param unit unit to convert to string
* @see stringToAreaUnit()
*/
static QString toString( AreaUnit unit );
Q_INVOKABLE static QString toString( AreaUnit unit );

/** Converts a translated string to an areal unit.
* @param string string representing an areal unit
* @param ok optional boolean, will be set to true if string was converted successfully
* @see toString()
*/
static AreaUnit stringToAreaUnit( const QString& string, bool *ok = 0 );
Q_INVOKABLE static AreaUnit stringToAreaUnit( const QString& string, bool *ok = 0 );

/** Returns the conversion factor between the specified areal units.
* @param fromUnit area unit to convert from
* @param toUnit area unit to convert to
* @returns multiplication factor to convert between units
*/
static double fromUnitToUnitFactor( AreaUnit fromUnit, AreaUnit toUnit );
Q_INVOKABLE static double fromUnitToUnitFactor( AreaUnit fromUnit, AreaUnit toUnit );

/** Converts a distance unit to its corresponding area unit, eg meters to square meters
* @param distanceUnit distance unit to convert
* @return matching areal unit
*/
static AreaUnit distanceToAreaUnit( QgsUnitTypes::DistanceUnit distanceUnit );
Q_INVOKABLE static AreaUnit distanceToAreaUnit( QgsUnitTypes::DistanceUnit distanceUnit );

// ANGULAR UNITS

@@ -193,35 +195,35 @@ class CORE_EXPORT QgsUnitTypes
* @returns encoded string
* @see decodeAngleUnit()
*/
static QString encodeUnit( AngleUnit unit );
Q_INVOKABLE static QString encodeUnit( AngleUnit unit );

/** Decodes an angular unit from a string.
* @param string string to decode
* @param ok optional boolean, will be set to true if string was converted successfully
* @returns decoded units
* @see encodeUnit()
*/
static AngleUnit decodeAngleUnit( const QString& string, bool *ok = 0 );
Q_INVOKABLE static AngleUnit decodeAngleUnit( const QString& string, bool *ok = 0 );

/** Returns a translated string representing an angular unit.
* @param unit unit to convert to string
*/
static QString toString( AngleUnit unit );
Q_INVOKABLE static QString toString( AngleUnit unit );

/** Returns the conversion factor between the specified angular units.
* @param fromUnit angle unit to convert from
* @param toUnit angle unit to convert to
* @returns multiplication factor to convert between units
*/
static double fromUnitToUnitFactor( AngleUnit fromUnit, AngleUnit toUnit );
Q_INVOKABLE static double fromUnitToUnitFactor( AngleUnit fromUnit, AngleUnit toUnit );

/** Returns an angle formatted as a friendly string.
* @param angle angle to format
* @param decimals number of decimal places to show
* @param unit unit of angle
* @returns formatted angle string
*/
static QString formatAngle( double angle, int decimals, AngleUnit unit );
Q_INVOKABLE static QString formatAngle( double angle, int decimals, AngleUnit unit );

// RENDER UNITS

@@ -230,15 +232,15 @@ class CORE_EXPORT QgsUnitTypes
* @returns encoded string
* @see decodeRenderUnit()
*/
static QString encodeUnit( RenderUnit unit );
Q_INVOKABLE static QString encodeUnit( RenderUnit unit );

/** Decodes a render unit from a string.
* @param string string to decode
* @param ok optional boolean, will be set to true if string was converted successfully
* @returns decoded units
* @see encodeUnit()
*/
static RenderUnit decodeRenderUnit( const QString& string, bool *ok = 0 );
Q_INVOKABLE static RenderUnit decodeRenderUnit( const QString& string, bool *ok = 0 );

};

0 comments on commit 3e83faf

Please sign in to comment.