Skip to content

Commit

Permalink
Add Distance*, Area*, Angle* prefixes to QgsUnitTypes enum values
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 25, 2016
1 parent 510f428 commit f6b09ea
Show file tree
Hide file tree
Showing 70 changed files with 921 additions and 904 deletions.
21 changes: 19 additions & 2 deletions doc/api_break.dox
Expand Up @@ -54,8 +54,8 @@ qgsPermissiveToInt()</li>
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>
Some of these unit types have also been renamed - see the notes on QgsUnitTypes below. 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>
Expand Down Expand Up @@ -468,6 +468,23 @@ parameters or QgsSymbolV2::OutputUnitList parameters now take QgsUnitTypes::Rend
use QgsTreeWidgetItemObject which is an upgraded version of the original QgsTreeWidgetItem</li>
</ul>

\subsection qgis_api_break_3_0_QgsUnitTypes QgsUnitTypes

<ul>
<li>All distance enumeration values were renamed to have a "Distance" prefix, including
Meters (to DistanceMeters), Kilometers (to DistanceKilometers), Feet (to DistanceFeet),
NauticalMiles (to DistanceNauticalMiles), Yards (to DistanceYards), Miles (to DistanceMiles),
Degrees (to DistanceDegrees) and UnknownDistanceUnit to DistanceUnknownUnit</li>
<li>All area enumeration values were renamed to have a "Area" prefix, including
SquareMeters (to AreaSquareMeters), SquareKilometers (to AreaSquareKilometers), SquareFeet (to AreaSquareFeet),
SquareYards (to AreaSquareYards), SquareMiles (to AreaSquareMiles), Hectares (to AreaHectares),
Acres (to AreaAcres), SquareNauticalMiles (to AreaSquareNauticalMiles), SquareDegrees (to AreaSquareDegrees)
and UnknownAreaUnit to AreaUnknownUnit</li>
<li>All angle enumeration values were renamed to have a "Angle" prefix, including
Radians (to AngleRadians), Gon (to AngleGon), MinutesOfArc (to AngleMinutesOfArc),
SecondsOfArc (to AngleSecondsOfArc), Turn (to AngleTurn) and UnknownAngleUnit to AngleUnknownUnit</li>
</ul>

\subsection qgis_api_break_3_0_QgsVectorLayer QgsVectorLayer

<ul>
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsscalecalculator.sip
Expand Up @@ -16,7 +16,7 @@ class QgsScaleCalculator
* @param mapUnits Units of the data on the map
*/
QgsScaleCalculator( double dpi = 0,
QgsUnitTypes::DistanceUnit mapUnits = QgsUnitTypes::Meters );
QgsUnitTypes::DistanceUnit mapUnits = QgsUnitTypes::DistanceMeters );

/**
* Set the dpi to be used in scale calculations
Expand Down
64 changes: 32 additions & 32 deletions python/core/qgsunittypes.sip
Expand Up @@ -15,65 +15,65 @@ class QgsUnitTypes
//! 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 */
DistanceMeters, /*!< meters */
DistanceKilometers, /*!< kilometers */
DistanceFeet, /*!< imperial feet */
DistanceNauticalMiles, /*!< nautical miles */
DistanceYards, /*!< imperial yards */
DistanceMiles, /*!< terrestial miles */
DistanceDegrees, /*!< degrees, for planar geographic CRS distance measurements */
DistanceUnknownUnit, /*!< unknown distance unit */
};

/** Types of distance units
*/
enum DistanceUnitType
{
Standard, /*!< unit is a standard measurement unit */
Geographic, /*!< unit is a geographic (eg degree based) unit */
UnknownType, /*!< unknown unit type */
Standard, /*!< unit is a standard measurement unit */
Geographic, /*!< unit is a geographic (eg degree based) unit */
UnknownType, /*!< unknown unit type */
};

//! Units of area
enum AreaUnit
{
SquareMeters, /*!< square meters */
SquareKilometers, /*!< square kilometers */
SquareFeet, /*!< square feet */
SquareYards, /*!< square yards */
SquareMiles, /*!< square miles */
Hectares, /*!< hectares */
Acres, /*!< acres */
SquareNauticalMiles, /*!< square nautical miles */
SquareDegrees, /*!< square degrees, for planar geographic CRS area measurements */
UnknownAreaUnit, /*!< unknown areal unit */
AreaSquareMeters, /*!< square meters */
AreaSquareKilometers, /*!< square kilometers */
AreaSquareFeet, /*!< square feet */
AreaSquareYards, /*!< square yards */
AreaSquareMiles, /*!< square miles */
AreaHectares, /*!< hectares */
AreaAcres, /*!< acres */
AreaSquareNauticalMiles, /*!< square nautical miles */
AreaSquareDegrees, /*!< square degrees, for planar geographic CRS area measurements */
AreaUnknownUnit, /*!< unknown areal unit */
};

//! Units of angles
enum AngleUnit
{
AngleDegrees = 0, /*!< degrees */
Radians, /*!< square kilometers */
Gon, /*!< gon/gradian */
MinutesOfArc, /*!< minutes of arc */
SecondsOfArc, /*!< seconds of arc */
Turn, /*!< turn/revolutions */
UnknownAngleUnit, /*!< unknown angle unit */
AngleDegrees, /*!< degrees */
AngleRadians, /*!< square kilometers */
AngleGon, /*!< gon/gradian */
AngleMinutesOfArc, /*!< minutes of arc */
AngleSecondsOfArc, /*!< seconds of arc */
AngleTurn, /*!< turn/revolutions */
AngleUnknownUnit, /*!< unknown angle unit */
};

//! List of render units
typedef QList<QgsUnitTypes::RenderUnit> RenderUnitList;

//! Rendering size units
enum RenderUnit
{
RenderMillimeters, //!< millimeters
RenderMapUnits, //!< map units
RenderPixels, //!< pixels
RenderPercentage, //!< percentage of another measurement (eg canvas size, feature size)
UnknownRenderUnit, //!< mixed or unknown units
RenderUnknownUnit, //!< mixed or unknown units
};

//! List of render units
typedef QList<QgsUnitTypes::RenderUnit> RenderUnitList;

/** Returns the type for a distance unit.
*/
static DistanceUnitType unitType( QgsUnitTypes::DistanceUnit unit );
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsvectorfilewriter.sip
Expand Up @@ -271,7 +271,7 @@ class QgsVectorFileWriter
QString errorMessage();

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

//! @note not available in python bindings
// QMap<int, int> attrIdxToOgrIdx();
Expand Down
2 changes: 1 addition & 1 deletion python/core/symbology-ng/qgssymbollayerv2.sip
Expand Up @@ -155,7 +155,7 @@ class QgsSymbolLayerV2
* symbol layer subclasses will interpret this in different ways, eg a marker symbol
* layer may use it to specify the units for the marker size, while a line symbol
* layer may use it to specify the units for the line width.
* @returns output unit, or UnknownRenderUnit if the symbol layer contains mixed units
* @returns output unit, or QgsUnitTypes::RenderUnknownUnit if the symbol layer contains mixed units
* @see setOutputUnit()
*/
virtual QgsUnitTypes::RenderUnit outputUnit() const;
Expand Down
2 changes: 1 addition & 1 deletion python/core/symbology-ng/qgssymbolv2.sip
Expand Up @@ -143,7 +143,7 @@ class QgsSymbolV2
* symbol layer definitions will interpret this in different ways, eg a marker symbol
* may use it to specify the units for the marker size, while a line symbol
* may use it to specify the units for the line width.
* @returns output unit, or UnknownRenderUnit if the symbol contains mixed units
* @returns output unit, or QgsUnitTypes::RenderUnknownUnit if the symbol contains mixed units
* @see setOutputUnit()
*/
QgsUnitTypes::RenderUnit outputUnit() const;
Expand Down
4 changes: 2 additions & 2 deletions src/analysis/vector/qgstransectsample.cpp
Expand Up @@ -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() == QgsUnitTypes::Degrees )
if ( mMinDistanceUnits == Meters && mStrataLayer->crs().mapUnits() == QgsUnitTypes::DistanceDegrees )
{
minDistanceLayerUnits = minDistance / 111319.9;
}
Expand Down Expand Up @@ -710,7 +710,7 @@ double QgsTransectSample::bufferDistance( double minDistanceFromAttribute ) cons
bufferDist = mBaselineBufferDistance;
}

if ( mMinDistanceUnits == Meters && mStrataLayer->crs().mapUnits() == QgsUnitTypes::Degrees )
if ( mMinDistanceUnits == Meters && mStrataLayer->crs().mapUnits() == QgsUnitTypes::DistanceDegrees )
{
bufferDist /= 111319.9;
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -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() != QgsUnitTypes::UnknownDistanceUnit )
if ( srs.mapUnits() != QgsUnitTypes::DistanceUnknownUnit )
{
mMapCanvas->setMapUnits( srs.mapUnits() );
}
Expand Down Expand Up @@ -8508,7 +8508,7 @@ void QgisApp::setProjectCrsFromLayer()
QgsCoordinateReferenceSystem crs = mLayerTreeView->currentLayer()->crs();
mMapCanvas->freeze();
mMapCanvas->setDestinationCrs( crs );
if ( crs.mapUnits() != QgsUnitTypes::UnknownDistanceUnit )
if ( crs.mapUnits() != QgsUnitTypes::DistanceUnknownUnit )
{
mMapCanvas->setMapUnits( crs.mapUnits() );
}
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsdecorationgrid.cpp
Expand Up @@ -94,7 +94,7 @@ void QgsDecorationGrid::projectRead()

mEnabled = QgsProject::instance()->readBoolEntry( mNameConfig, "/Enabled", false );
mMapUnits = static_cast< QgsUnitTypes::DistanceUnit >( QgsProject::instance()->readNumEntry( mNameConfig, "/MapUnits",
QgsUnitTypes::UnknownDistanceUnit ) );
QgsUnitTypes::DistanceUnknownUnit ) );
mGridStyle = static_cast< GridStyle >( QgsProject::instance()->readNumEntry( mNameConfig, "/Style",
QgsDecorationGrid::Line ) );
mGridIntervalX = QgsProject::instance()->readDoubleEntry( mNameConfig, "/IntervalX", 10 );
Expand Down Expand Up @@ -751,7 +751,7 @@ void QgsDecorationGrid::checkMapUnitsChanged()
if ( mEnabled && ( mMapUnits != mapUnits ) )
{
mEnabled = false;
mMapUnits = QgsUnitTypes::UnknownDistanceUnit; // make sure isDirty() returns true
mMapUnits = QgsUnitTypes::DistanceUnknownUnit; // make sure isDirty() returns true
if ( ! QgisApp::instance()->mapCanvas()->isFrozen() )
{
update();
Expand All @@ -763,7 +763,7 @@ bool QgsDecorationGrid::isDirty()
{
// checks if stored map units is undefined or different from canvas map units
// or if interval is 0
if ( mMapUnits == QgsUnitTypes::UnknownDistanceUnit ||
if ( mMapUnits == QgsUnitTypes::DistanceUnknownUnit ||
mMapUnits != QgisApp::instance()->mapCanvas()->mapSettings().mapUnits() ||
qgsDoubleNear( mGridIntervalX, 0.0 ) || qgsDoubleNear( mGridIntervalY, 0.0 ) )
return true;
Expand All @@ -774,7 +774,7 @@ void QgsDecorationGrid::setDirty( bool dirty )
{
if ( dirty )
{
mMapUnits = QgsUnitTypes::UnknownDistanceUnit;
mMapUnits = QgsUnitTypes::DistanceUnknownUnit;
}
else
{
Expand Down
10 changes: 5 additions & 5 deletions src/app/qgsdecorationscalebar.cpp
Expand Up @@ -135,7 +135,7 @@ void QgsDecorationScaleBar::render( QPainter * theQPainter )
bool ok = false;
QgsUnitTypes::DistanceUnit myPreferredUnits = QgsUnitTypes::decodeDistanceUnit( settings.value( "/qgis/measure/displayunits" ).toString(), &ok );
if ( !ok )
myPreferredUnits = QgsUnitTypes::Meters;
myPreferredUnits = QgsUnitTypes::DistanceMeters;
QgsUnitTypes::DistanceUnit myMapUnits = canvas->mapUnits();

// Adjust units meter/feet/... or vice versa
Expand Down Expand Up @@ -175,7 +175,7 @@ void QgsDecorationScaleBar::render( QPainter * theQPainter )
QString myScaleBarUnitLabel;
switch ( myMapUnits )
{
case QgsUnitTypes::Meters:
case QgsUnitTypes::DistanceMeters:
if ( myActualSize > 1000.0 )
{
myScaleBarUnitLabel = tr( " km" );
Expand All @@ -194,7 +194,7 @@ void QgsDecorationScaleBar::render( QPainter * theQPainter )
else
myScaleBarUnitLabel = tr( " m" );
break;
case QgsUnitTypes::Feet:
case QgsUnitTypes::DistanceFeet:
if ( myActualSize > 5280.0 ) //5280 feet to the mile
{
myScaleBarUnitLabel = tr( " miles" );
Expand Down Expand Up @@ -224,13 +224,13 @@ void QgsDecorationScaleBar::render( QPainter * theQPainter )
myScaleBarUnitLabel = tr( " feet" );
}
break;
case QgsUnitTypes::Degrees:
case QgsUnitTypes::DistanceDegrees:
if ( myActualSize == 1.0 )
myScaleBarUnitLabel = tr( " degree" );
else
myScaleBarUnitLabel = tr( " degrees" );
break;
case QgsUnitTypes::UnknownDistanceUnit:
case QgsUnitTypes::DistanceUnknownUnit:
myScaleBarUnitLabel = tr( " unknown" );
//intentional fall-through
FALLTHROUGH;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsdisplayangle.cpp
Expand Up @@ -44,5 +44,5 @@ void QgsDisplayAngle::updateUi()
QSettings settings;
QgsUnitTypes::AngleUnit unit = QgsUnitTypes::decodeAngleUnit( settings.value( "/qgis/measure/angleunits", QgsUnitTypes::encodeUnit( QgsUnitTypes::AngleDegrees ) ).toString() );
int decimals = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();
mAngleLineEdit->setText( QgsUnitTypes::formatAngle( mValue * QgsUnitTypes::fromUnitToUnitFactor( QgsUnitTypes::Radians, unit ), decimals, unit ) );
mAngleLineEdit->setText( QgsUnitTypes::formatAngle( mValue * QgsUnitTypes::fromUnitToUnitFactor( QgsUnitTypes::AngleRadians, unit ), decimals, unit ) );
}
2 changes: 1 addition & 1 deletion src/app/qgsmaptooloffsetpointsymbol.cpp
Expand Up @@ -244,7 +244,7 @@ QPointF QgsMapToolOffsetPointSymbol::calculateOffset( const QgsPoint& startPoint
factor = 1.0;
break;

case QgsUnitTypes::UnknownRenderUnit:
case QgsUnitTypes::RenderUnknownUnit:
case QgsUnitTypes::RenderPercentage:
//no sensible value
factor = 1.0;
Expand Down

0 comments on commit f6b09ea

Please sign in to comment.