Skip to content
Permalink
Browse files

Move QGis::UnitType to QgsUnitTypes::DistanceUnit

This change consolidates more unit handling and conversion into
QgsUnitTypes.

Additionally, UnknownUnit was renamed to UnknownDistanceUnit.
All methods which accepted QGis::UnitType parameters have been
updated to take QgsUnitTypes::DistanceUnit instead.

ALso remove the unit handling methods toLiteral, fromLiteral, tr,
fromTr, and fromUnitToUnitFactor from QGis. Their corresponding
counterparts in QgsUnitTypes should be used instead.
  • Loading branch information
nyalldawson committed Jul 17, 2016
1 parent 59aed7b commit f6f5010131f0da640516db9e8807407e07206bce
Showing with 572 additions and 662 deletions.
  1. +6 −0 doc/api_break.dox
  2. +3 −3 python/core/dxf/qgsdxfexport.sip
  3. +0 −38 python/core/qgis.sip
  4. +1 −1 python/core/qgscoordinatereferencesystem.sip
  5. +5 −5 python/core/qgsdistancearea.sip
  6. +2 −2 python/core/qgsexpression.sip
  7. +2 −2 python/core/qgsmapsettings.sip
  8. +1 −1 python/core/qgsproject.sip
  9. +4 −5 python/core/qgsscalecalculator.sip
  10. +20 −7 python/core/qgsunittypes.sip
  11. +1 −1 python/core/qgsvectorfilewriter.sip
  12. +2 −2 python/core/qgsxmlutils.sip
  13. +2 −2 python/gui/qgsmapcanvas.sip
  14. +3 −3 python/gui/qgsmaptoolidentify.sip
  15. +2 −2 python/server/qgsmaprenderer.sip
  16. +2 −2 src/analysis/vector/qgstransectsample.cpp
  17. +2 −2 src/app/qgisapp.cpp
  18. +6 −6 src/app/qgsdecorationgrid.cpp
  19. +3 −3 src/app/qgsdecorationgrid.h
  20. +7 −7 src/app/qgsdecorationscalebar.cpp
  21. +1 −1 src/app/qgsmaptoolidentifyaction.cpp
  22. +1 −1 src/app/qgsmaptoolidentifyaction.h
  23. +16 −16 src/app/qgsmeasuredialog.cpp
  24. +3 −3 src/app/qgsmeasuredialog.h
  25. +11 −11 src/app/qgsoptions.cpp
  26. +17 −17 src/app/qgsprojectproperties.cpp
  27. +4 −3 src/app/qgsprojectproperties.h
  28. +4 −4 src/core/composer/qgscomposerscalebar.cpp
  29. +5 −5 src/core/dxf/qgsdxfexport.cpp
  30. +4 −4 src/core/dxf/qgsdxfexport.h
  31. +0 −45 src/core/qgis.cpp
  32. +0 −38 src/core/qgis.h
  33. +10 −10 src/core/qgscoordinatereferencesystem.cpp
  34. +2 −2 src/core/qgscoordinatereferencesystem.h
  35. +2 −2 src/core/qgscoordinatereferencesystem_p.h
  36. +25 −25 src/core/qgsdistancearea.cpp
  37. +6 −6 src/core/qgsdistancearea.h
  38. +2 −2 src/core/qgsexpression.cpp
  39. +2 −2 src/core/qgsexpression.h
  40. +2 −2 src/core/qgsexpressionprivate.h
  41. +4 −4 src/core/qgsmapsettings.cpp
  42. +2 −2 src/core/qgsmapsettings.h
  43. +3 −3 src/core/qgsproject.cpp
  44. +1 −1 src/core/qgsproject.h
  45. +7 −7 src/core/qgsscalecalculator.cpp
  46. +6 −6 src/core/qgsscalecalculator.h
  47. +145 −145 src/core/qgsunittypes.cpp
  48. +20 −7 src/core/qgsunittypes.h
  49. +8 −8 src/core/qgsvectorfilewriter.cpp
  50. +4 −4 src/core/qgsvectorfilewriter.h
  51. +2 −2 src/core/qgsvectorlayereditutils.cpp
  52. +13 −13 src/core/qgsxmlutils.cpp
  53. +3 −2 src/core/qgsxmlutils.h
  54. +2 −2 src/gui/qgsmapcanvas.cpp
  55. +2 −2 src/gui/qgsmapcanvas.h
  56. +4 −4 src/gui/qgsmaptoolidentify.cpp
  57. +3 −3 src/gui/qgsmaptoolidentify.h
  58. +3 −3 src/plugins/coordinate_capture/coordinatecapture.cpp
  59. +1 −1 src/plugins/grass/qgsgrassnewmapset.cpp
  60. +2 −2 src/plugins/grass/qgsgrassregion.cpp
  61. +1 −1 src/providers/arcgisrest/qgsamsprovider.cpp
  62. +3 −3 src/providers/wcs/qgswcsprovider.cpp
  63. +2 −2 src/providers/wfs/qgswfsshareddata.cpp
  64. +2 −2 src/providers/wms/qgswmscapabilities.cpp
  65. +3 −3 src/providers/wms/qgswmsprovider.cpp
  66. +3 −3 src/server/qgsmaprenderer.cpp
  67. +2 −2 src/server/qgsmaprenderer.h
  68. +1 −1 src/server/qgswmsserver.cpp
  69. +2 −2 tests/src/app/testqgsattributetable.cpp
  70. +2 −2 tests/src/app/testqgsfieldcalculator.cpp
  71. +4 −4 tests/src/app/testqgsmaptoolidentifyaction.cpp
  72. +2 −2 tests/src/app/testqgsmeasuretool.cpp
  73. +1 −1 tests/src/core/testqgsatlascomposition.cpp
  74. +1 −1 tests/src/core/testqgscomposerdd.cpp
  75. +1 −1 tests/src/core/testqgscomposition.cpp
  76. +4 −4 tests/src/core/testqgscoordinatereferencesystem.cpp
  77. +8 −8 tests/src/core/testqgsdistancearea.cpp
  78. +10 −10 tests/src/core/testqgsexpression.cpp
  79. +6 −6 tests/src/core/testqgsproject.cpp
  80. +2 −2 tests/src/python/test_qgsatlascomposition.py
  81. +37 −38 tests/src/python/test_qgsdistancearea.py
  82. +47 −48 tests/src/python/test_qgsunittypes.py
  83. +2 −2 tests/src/python/test_qgsvectorlayer.py
@@ -52,6 +52,12 @@ qgsPermissiveToInt()</li>
<li>The constants DEFAULT_IDENTIFY_RADIUS and MINIMUM_POINT_SIZE were removed</li>
<li>QGis::DecimalDegrees, DegreesMinutesSeconds and DegreesDecimalMinutes have been removed, and have all been replaced
with the general Degrees unit</li>
<li>The distance unit types QGis::UnitType (including QGis::Meters, QGis::Feet, QGis::Degrees, QGis::NauticalMiles,
QGis::Kilometers, QGis::Yards, QGis::Miles and QGis::UnknownUnit have been moved to QgsUnitTypes::DistanceUnit.
Additionally, UnknownUnit was renamed to UnknownDistanceUnit. All methods which accepted QGis::UnitType parameters
have been updated to take QgsUnitTypes::DistanceUnit instead.</li>
<li>The unit handling methods toLiteral, fromLiteral, tr, fromTr, fromUnitToUnitFactor have been removed. Their
corresponding counterparts in QgsUnitTypes should be used instead.</li>
</ul>

\subsection qgis_api_break_3_0_QgsAuthConfigUriEdit QgsAuthConfigUriEdit
@@ -63,14 +63,14 @@ class QgsDxfExport
* Set map units
* @param u unit
*/
void setMapUnits( Qgis::UnitType u );
void setMapUnits( QgsUnitTypes::DistanceUnit u );

/**
* Retrieve map units
* @returns unit
* @see setMapUnits
*/
Qgis::UnitType mapUnits() const;
QgsUnitTypes::DistanceUnit mapUnits() const;

/**
* Set symbology export mode
@@ -327,7 +327,7 @@ class QgsDxfExport
//! @note added in 2.15
void writeMText( const QString &layer, const QString &text, const QgsPointV2 &pt, double width, double angle, const QColor& color );

static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, Qgis::UnitType mapUnits );
static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QgsUnitTypes::DistanceUnit mapUnits );

//! Return cleaned layer name for use in DXF
static QString dxfLayerName( const QString &name );
@@ -136,44 +136,6 @@ class Qgis
QImage::Format_ARGB32_Premultiplied */ ARGB32_Premultiplied,
};


/** Map units that qgis supports
* @note that QGIS < 1.4 api had only Meters, Feet, Degrees and UnknownUnit
* @note and QGIS >1.8 returns to that
*/
//TODO QGIS 3.0 - clean up and move to QgsUnitTypes and rename to DistanceUnit
enum UnitType
{
Meters, /*!< meters */
Feet, /*!< imperial feet */
Degrees, /*!< degrees, for planar geographic CRS distance measurements */ //for 1.0 api backwards compatibility
NauticalMiles, /*!< nautical miles */
Kilometers, /*!< kilometers */
Yards, /*!< imperial yards */
Miles, /*!< terrestial miles */
UnknownUnit, /*!< unknown distance unit */
};

//! Provides the canonical name of the type value
//! @deprecated use QgsUnitTypes::encodeUnit() instead
static QString toLiteral( Qgis::UnitType unit ) /Deprecated/;

//! Converts from the canonical name to the type value
//! @deprecated use QgsUnitTypes::decodeDistanceUnit() instead
static UnitType fromLiteral( const QString& literal, Qgis::UnitType defaultType = UnknownUnit ) /Deprecated/;

//! Provides translated version of the type value
//! @deprecated use QgsUnitTypes::toString() instead
static QString tr( Qgis::UnitType unit ) /Deprecated/;

//! Provides type value from translated version
//! @deprecated use QgsUnitTypes::stringToDistanceUnit() instead
static UnitType fromTr( const QString& literal, Qgis::UnitType defaultType = UnknownUnit ) /Deprecated/;

//! Returns the conversion factor between the specified units
//! @deprecated use QgsUnitTyoes::fromUnitToUnitFactor() instead
static double fromUnitToUnitFactor( Qgis::UnitType fromUnit, Qgis::UnitType toUnit ) /Deprecated/;

//! User defined event types
enum UserEvent
{
@@ -446,7 +446,7 @@ class QgsCoordinateReferenceSystem

/** Returns the units for the projection used by the CRS.
*/
Qgis::UnitType mapUnits() const;
QgsUnitTypes::DistanceUnit mapUnits() const;


// Mutators -----------------------------------
@@ -155,7 +155,7 @@ class QgsDistanceArea
* @note added in QGIS 2.14
* @see areaUnits()
*/
Qgis::UnitType lengthUnits() const;
QgsUnitTypes::DistanceUnit lengthUnits() const;

/** Returns the units of area for areal calculations made by this object.
* @note added in QGIS 2.14
@@ -179,7 +179,7 @@ class QgsDistanceArea
* @return formatted measurement string
* @deprecated use formatDistance() or formatArea() instead
*/
static QString textUnit( double value, int decimals, Qgis::UnitType u, bool isArea, bool keepBaseUnit = false ) /Deprecated/;
static QString textUnit( double value, int decimals, QgsUnitTypes::DistanceUnit u, bool isArea, bool keepBaseUnit = false ) /Deprecated/;

/** Returns an distance formatted as a friendly string.
* @param distance distance to format
@@ -191,7 +191,7 @@ class QgsDistanceArea
* @note added in QGIS 2.16
* @see formatArea()
*/
static QString formatDistance( double distance, int decimals, Qgis::UnitType unit, bool keepBaseUnit = false );
static QString formatDistance( double distance, int decimals, QgsUnitTypes::DistanceUnit unit, bool keepBaseUnit = false );

/** Returns an area formatted as a friendly string.
* @param area area to format
@@ -208,7 +208,7 @@ class QgsDistanceArea

//! Helper for conversion between physical units
// TODO QGIS 3.0 - remove this method, as its behaviour is non-intuitive.
void convertMeasurement( double &measure /In,Out/, Qgis::UnitType &measureUnits /In,Out/, Qgis::UnitType displayUnits, bool isArea ) const;
void convertMeasurement( double &measure /In,Out/, QgsUnitTypes::DistanceUnit &measureUnits /In,Out/, QgsUnitTypes::DistanceUnit displayUnits, bool isArea ) const;

/** Takes a length measurement calculated by this QgsDistanceArea object and converts it to a
* different distance unit.
@@ -219,7 +219,7 @@ class QgsDistanceArea
* @see convertAreaMeasurement()
* @note added in QGIS 2.14
*/
double convertLengthMeasurement( double length, Qgis::UnitType toUnits ) const;
double convertLengthMeasurement( double length, QgsUnitTypes::DistanceUnit toUnits ) const;

/** Takes an area measurement calculated by this QgsDistanceArea object and converts it to a
* different areal unit.
@@ -167,14 +167,14 @@ class QgsExpression
* @note added in QGIS 2.14
* @see setDistanceUnits()
*/
Qgis::UnitType distanceUnits() const;
QgsUnitTypes::DistanceUnit distanceUnits() const;

/** Sets the desired distance units for calculations involving geomCalculator(), eg "$length" and "$perimeter".
* @note distances are only converted when a geomCalculator() has been set
* @note added in QGIS 2.14
* @see distanceUnits()
*/
void setDistanceUnits( Qgis::UnitType unit );
void setDistanceUnits( QgsUnitTypes::DistanceUnit unit );

/** Returns the desired areal units for calculations involving geomCalculator(), eg "$area".
* @note areas are only converted when a geomCalculator() has been set
@@ -91,9 +91,9 @@ class QgsMapSettings
QgsCoordinateReferenceSystem destinationCrs() const;

//! Get units of map's geographical coordinates - used for scale calculation
Qgis::UnitType mapUnits() const;
QgsUnitTypes::DistanceUnit mapUnits() const;
//! Set units of map's geographical coordinates - used for scale calculation
void setMapUnits( Qgis::UnitType u );
void setMapUnits( QgsUnitTypes::DistanceUnit u );

//! Set the background color of the map
void setBackgroundColor( const QColor& color );
@@ -246,7 +246,7 @@ class QgsProject : QObject
* @note added in QGIS 2.14
* @see areaUnits()
*/
Qgis::UnitType distanceUnits() const;
QgsUnitTypes::DistanceUnit distanceUnits() const;

/** Convenience function to query default area measurement units for project.
* @note added in QGIS 2.14
@@ -13,11 +13,10 @@ class QgsScaleCalculator
/**
* Constructor
* @param dpi Monitor resolution in dots per inch
* @param mapUnits Units of the data on the map. Must match a value from the
* Qgis::UnitType enum (Meters, Feet, Degrees)
* @param mapUnits Units of the data on the map
*/
QgsScaleCalculator( double dpi = 0,
Qgis::UnitType mapUnits = Qgis::Meters );
QgsUnitTypes::DistanceUnit mapUnits = QgsUnitTypes::Meters );

/**
* Set the dpi to be used in scale calculations
@@ -35,10 +34,10 @@ class QgsScaleCalculator
* Set the map units
* @param mapUnits Units of the data on the map. Must match a value from the
*/
void setMapUnits( Qgis::UnitType mapUnits );
void setMapUnits( QgsUnitTypes::DistanceUnit mapUnits );

/** Returns current map units */
Qgis::UnitType mapUnits() const;
QgsUnitTypes::DistanceUnit mapUnits() const;

/**
* Calculate the scale denominator
@@ -12,6 +12,19 @@ class QgsUnitTypes

public:

//! Units of distance
enum DistanceUnit
{
Meters, /*!< meters */
Kilometers, /*!< kilometers */
Feet, /*!< imperial feet */
NauticalMiles, /*!< nautical miles */
Yards, /*!< imperial yards */
Miles, /*!< terrestial miles */
Degrees, /*!< degrees, for planar geographic CRS distance measurements */
UnknownDistanceUnit, /*!< unknown distance unit */
};

/** Types of distance units
*/
enum DistanceUnitType
@@ -50,42 +63,42 @@ class QgsUnitTypes

/** Returns the type for a distance unit.
*/
static DistanceUnitType unitType( Qgis::UnitType unit );
static DistanceUnitType unitType( QgsUnitTypes::DistanceUnit unit );

/** Encodes a distance unit to a string.
* @param unit unit to encode
* @returns encoded string
* @see decodeDistanceUnit()
*/
static QString encodeUnit( Qgis::UnitType unit );
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 Qgis::UnitType decodeDistanceUnit( const QString& string, bool *ok = 0 );
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( Qgis::UnitType unit );
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 Qgis::UnitType stringToDistanceUnit( const QString& string, bool *ok = 0 );
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( Qgis::UnitType fromUnit, Qgis::UnitType toUnit );
static double fromUnitToUnitFactor( QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit );

/** Returns the type for an areal unit.
*/
@@ -130,7 +143,7 @@ class QgsUnitTypes
* @param distanceUnit distance unit to convert
* @return matching areal unit
*/
static AreaUnit distanceToAreaUnit( Qgis::UnitType distanceUnit );
static AreaUnit distanceToAreaUnit( QgsUnitTypes::DistanceUnit distanceUnit );

// ANGULAR UNITS

@@ -271,7 +271,7 @@ class QgsVectorFileWriter
QString errorMessage();

/** Add feature to the currently opened data source */
bool addFeature( QgsFeature& feature, QgsFeatureRendererV2* renderer = 0, Qgis::UnitType outputUnit = Qgis::Meters );
bool addFeature( QgsFeature& feature, QgsFeatureRendererV2* renderer = 0, QgsUnitTypes::DistanceUnit outputUnit = QgsUnitTypes::Meters );

//! @note not available in python bindings
// QMap<int, int> attrIdxToOgrIdx();
@@ -10,11 +10,11 @@ class QgsXmlUtils

/* reading */

static Qgis::UnitType readMapUnits( const QDomElement& element );
static QgsUnitTypes::DistanceUnit readMapUnits( const QDomElement& element );
static QgsRectangle readRectangle( const QDomElement& element );

/* writing */

static QDomElement writeMapUnits( Qgis::UnitType units, QDomDocument& doc );
static QDomElement writeMapUnits( QgsUnitTypes::DistanceUnit units, QDomDocument& doc );
static QDomElement writeRectangle( const QgsRectangle& rect, QDomDocument& doc );
};
@@ -223,10 +223,10 @@ class QgsMapCanvas : QGraphicsView
bool isFrozen();

//! Set map units (needed by project properties dialog)
void setMapUnits( Qgis::UnitType mapUnits );
void setMapUnits( QgsUnitTypes::DistanceUnit mapUnits );

//! Get the current canvas map units
Qgis::UnitType mapUnits() const;
QgsUnitTypes::DistanceUnit mapUnits() const;

//! Getter for stored overrides of styles for layers.
//! @note added in 2.12
@@ -114,18 +114,18 @@ class QgsMapToolIdentify : QgsMapTool

//! Private helper
//! @deprecated use displayDistanceUnits() and displayAreaUnits() instead
virtual void convertMeasurement( QgsDistanceArea &calc, double &measure, Qgis::UnitType &u, bool isArea ) /Deprecated/;
virtual void convertMeasurement( QgsDistanceArea &calc, double &measure, QgsUnitTypes::DistanceUnit &u, bool isArea ) /Deprecated/;

/** Transforms the measurements of derived attributes in the desired units
* @deprecated use displayDistanceUnits() and displayAreaUnits() instead
*/
virtual Qgis::UnitType displayUnits() /Deprecated/;
virtual QgsUnitTypes::DistanceUnit displayUnits() /Deprecated/;

/** Desired units for distance display.
* @note added in QGIS 2.14
* @see displayAreaUnits()
*/
virtual Qgis::UnitType displayDistanceUnits() const;
virtual QgsUnitTypes::DistanceUnit displayDistanceUnits() const;

/** Desired units for area display.
* @note added in QGIS 2.14
@@ -74,8 +74,8 @@ class QgsMapRenderer : QObject
//! Recalculate the map scale
void updateScale();

Qgis::UnitType mapUnits() const;
void setMapUnits( Qgis::UnitType u );
QgsUnitTypes::DistanceUnit mapUnits() const;
void setMapUnits( QgsUnitTypes::DistanceUnit u );

//! sets whether map image will be for overview
void enableOverviewMode( bool isOverview = true );
@@ -181,7 +181,7 @@ int QgsTransectSample::createSample( QProgressDialog* pd )
double minDistanceLayerUnits = minDistance;
//if minDistance is in meters and the data in degrees, we need to apply a rough conversion for the buffer distance
double bufferDist = bufferDistance( minDistance );
if ( mMinDistanceUnits == Meters && mStrataLayer->crs().mapUnits() == Qgis::Degrees )
if ( mMinDistanceUnits == Meters && mStrataLayer->crs().mapUnits() == QgsUnitTypes::Degrees )
{
minDistanceLayerUnits = minDistance / 111319.9;
}
@@ -710,7 +710,7 @@ double QgsTransectSample::bufferDistance( double minDistanceFromAttribute ) cons
bufferDist = mBaselineBufferDistance;
}

if ( mMinDistanceUnits == Meters && mStrataLayer->crs().mapUnits() == Qgis::Degrees )
if ( mMinDistanceUnits == Meters && mStrataLayer->crs().mapUnits() == QgsUnitTypes::Degrees )
{
bufferDist /= 111319.9;
}
@@ -4420,7 +4420,7 @@ void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )
prj->writeEntry( "SpatialRefSys", "/ProjectCrs", srs.authid() );
prj->writeEntry( "SpatialRefSys", "/ProjectCRSID", static_cast< int >( srs.srsid() ) );
prj->setDirty( false );
if ( srs.mapUnits() != Qgis::UnknownUnit )
if ( srs.mapUnits() != QgsUnitTypes::UnknownDistanceUnit )
{
mMapCanvas->setMapUnits( srs.mapUnits() );
}
@@ -8508,7 +8508,7 @@ void QgisApp::setProjectCrsFromLayer()
QgsCoordinateReferenceSystem crs = mLayerTreeView->currentLayer()->crs();
mMapCanvas->freeze();
mMapCanvas->setDestinationCrs( crs );
if ( crs.mapUnits() != Qgis::UnknownUnit )
if ( crs.mapUnits() != QgsUnitTypes::UnknownDistanceUnit )
{
mMapCanvas->setMapUnits( crs.mapUnits() );
}

0 comments on commit f6f5010

Please sign in to comment.
You can’t perform that action at this time.