mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Move handling of angular units to QgsUnitTypes, swap angle and distance
radio buttons to combo boxes in options dialog for consistency with project properties
This commit is contained in:
parent
dfdcec8922
commit
6dc0b6910f
@ -36,6 +36,18 @@ class QgsUnitTypes
|
||||
UnknownAreaUnit, /*!< 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 */
|
||||
};
|
||||
|
||||
/** Returns the type for a distance unit.
|
||||
*/
|
||||
static DistanceUnitType unitType( QGis::UnitType unit );
|
||||
@ -120,5 +132,41 @@ class QgsUnitTypes
|
||||
*/
|
||||
static AreaUnit distanceToAreaUnit( QGis::UnitType distanceUnit );
|
||||
|
||||
// ANGULAR UNITS
|
||||
|
||||
/** Encodes an angular unit to a string.
|
||||
* @param unit unit to encode
|
||||
* @returns encoded string
|
||||
* @see decodeAngleUnit()
|
||||
*/
|
||||
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 );
|
||||
|
||||
/** Returns a translated string representing an angular unit.
|
||||
* @param unit unit to convert to string
|
||||
*/
|
||||
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 );
|
||||
|
||||
/** 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 );
|
||||
};
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "qgsdisplayangle.h"
|
||||
#include "qgsmapcanvas.h"
|
||||
#include "qgslogger.h"
|
||||
#include "qgsunittypes.h"
|
||||
|
||||
#include <QSettings>
|
||||
#include <cmath>
|
||||
@ -41,23 +42,7 @@ void QgsDisplayAngle::setValueInRadians( double value )
|
||||
void QgsDisplayAngle::updateUi()
|
||||
{
|
||||
QSettings settings;
|
||||
QString unitString = settings.value( "/qgis/measure/angleunits", "degrees" ).toString();
|
||||
QgsUnitTypes::AngleUnit unit = QgsUnitTypes::decodeAngleUnit( settings.value( "/qgis/measure/angleunits", QgsUnitTypes::encodeUnit( QgsUnitTypes::AngleDegrees ) ).toString() );
|
||||
int decimals = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();
|
||||
|
||||
if ( unitString == "degrees" )
|
||||
{
|
||||
mAngleLineEdit->setText( tr( "%1 degrees" ).arg( QLocale::system().toString( mValue * 180 / M_PI ),
|
||||
'f', decimals ) );
|
||||
}
|
||||
else if ( unitString == "radians" )
|
||||
{
|
||||
mAngleLineEdit->setText( tr( "%1 radians" ).arg( QLocale::system().toString( mValue ),
|
||||
'f', decimals ) );
|
||||
|
||||
}
|
||||
else if ( unitString == "gon" )
|
||||
{
|
||||
mAngleLineEdit->setText( tr( "%1 gon" ).arg( QLocale::system().toString( mValue / M_PI * 200 ),
|
||||
'f', decimals ) );
|
||||
}
|
||||
mAngleLineEdit->setText( QgsUnitTypes::formatAngle( mValue * QgsUnitTypes::fromUnitToUnitFactor( QgsUnitTypes::Radians, unit ), decimals, unit ) );
|
||||
}
|
||||
|
@ -460,27 +460,17 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl ) :
|
||||
}
|
||||
|
||||
// Set the units for measuring
|
||||
bool ok = false;
|
||||
QGis::UnitType myDisplayUnits = QgsUnitTypes::decodeDistanceUnit( mSettings->value( "/qgis/measure/displayunits" ).toString(), &ok );
|
||||
if ( !ok )
|
||||
myDisplayUnits = QGis::Meters;
|
||||
mDistanceUnitsComboBox->addItem( tr( "Meters" ), QGis::Meters );
|
||||
mDistanceUnitsComboBox->addItem( tr( "Feet" ), QGis::Feet );
|
||||
mDistanceUnitsComboBox->addItem( tr( "Nautical miles" ), QGis::NauticalMiles );
|
||||
mDistanceUnitsComboBox->addItem( tr( "Degrees" ), QGis::Degrees );
|
||||
mDistanceUnitsComboBox->addItem( tr( "Map units" ), QGis::UnknownUnit );
|
||||
|
||||
if ( myDisplayUnits == QGis::Feet )
|
||||
{
|
||||
radFeet->setChecked( true );
|
||||
}
|
||||
else if ( myDisplayUnits == QGis::NauticalMiles )
|
||||
{
|
||||
radNautical->setChecked( true );
|
||||
}
|
||||
else if ( myDisplayUnits == QGis::Degrees )
|
||||
{
|
||||
radDegrees->setChecked( true );
|
||||
}
|
||||
else
|
||||
{
|
||||
radMeters->setChecked( true );
|
||||
}
|
||||
bool ok = false;
|
||||
QGis::UnitType distanceUnits = QgsUnitTypes::decodeDistanceUnit( mSettings->value( "/qgis/measure/displayunits" ).toString(), &ok );
|
||||
if ( !ok )
|
||||
distanceUnits = QGis::Meters;
|
||||
mDistanceUnitsComboBox->setCurrentIndex( mDistanceUnitsComboBox->findData( distanceUnits ) );
|
||||
|
||||
mAreaUnitsComboBox->addItem( tr( "Square meters" ), QgsUnitTypes::SquareMeters );
|
||||
mAreaUnitsComboBox->addItem( tr( "Square kilometers" ), QgsUnitTypes::SquareKilometers );
|
||||
@ -498,24 +488,15 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl ) :
|
||||
areaUnits = QgsUnitTypes::SquareMeters;
|
||||
mAreaUnitsComboBox->setCurrentIndex( mAreaUnitsComboBox->findData( areaUnits ) );
|
||||
|
||||
QButtonGroup* angleButtonGroup = new QButtonGroup( this );
|
||||
angleButtonGroup->addButton( mDegreesRadioButton );
|
||||
angleButtonGroup->addButton( mRadiansRadioButton );
|
||||
angleButtonGroup->addButton( mGonRadioButton );
|
||||
mAngleUnitsComboBox->addItem( tr( "Degrees" ), QgsUnitTypes::AngleDegrees );
|
||||
mAngleUnitsComboBox->addItem( tr( "Radians" ), QgsUnitTypes::Radians );
|
||||
mAngleUnitsComboBox->addItem( tr( "Gon/gradians" ), QgsUnitTypes::Gon );
|
||||
mAngleUnitsComboBox->addItem( tr( "Minutes of arc" ), QgsUnitTypes::MinutesOfArc );
|
||||
mAngleUnitsComboBox->addItem( tr( "Seconds of arc" ), QgsUnitTypes::SecondsOfArc );
|
||||
mAngleUnitsComboBox->addItem( tr( "Turns/revolutions" ), QgsUnitTypes::Turn );
|
||||
|
||||
QString myAngleUnitsTxt = mSettings->value( "/qgis/measure/angleunits", "degrees" ).toString();
|
||||
if ( myAngleUnitsTxt == "gon" )
|
||||
{
|
||||
mGonRadioButton->setChecked( true );
|
||||
}
|
||||
else if ( myAngleUnitsTxt == "radians" )
|
||||
{
|
||||
mRadiansRadioButton->setChecked( true );
|
||||
}
|
||||
else //degrees
|
||||
{
|
||||
mDegreesRadioButton->setChecked( true );
|
||||
}
|
||||
QgsUnitTypes::AngleUnit unit = QgsUnitTypes::decodeAngleUnit( mSettings->value( "/qgis/measure/angleunits", QgsUnitTypes::encodeUnit( QgsUnitTypes::AngleDegrees ) ).toString() );
|
||||
mAngleUnitsComboBox->setCurrentIndex( mAngleUnitsComboBox->findData( unit ) );
|
||||
|
||||
// set decimal places of the measure tool
|
||||
int decimalPlaces = mSettings->value( "/qgis/measure/decimalplaces", "3" ).toInt();
|
||||
@ -1262,36 +1243,16 @@ void QgsOptions::saveOptions()
|
||||
|
||||
mSettings->setValue( "/Projections/showDatumTransformDialog", chkShowDatumTransformDialog->isChecked() );
|
||||
|
||||
if ( radFeet->isChecked() )
|
||||
{
|
||||
mSettings->setValue( "/qgis/measure/displayunits", QgsUnitTypes::encodeUnit( QGis::Feet ) );
|
||||
}
|
||||
else if ( radNautical->isChecked() )
|
||||
{
|
||||
mSettings->setValue( "/qgis/measure/displayunits", QgsUnitTypes::encodeUnit( QGis::NauticalMiles ) );
|
||||
}
|
||||
else if ( radDegrees->isChecked() )
|
||||
{
|
||||
mSettings->setValue( "/qgis/measure/displayunits", QgsUnitTypes::encodeUnit( QGis::Degrees ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
mSettings->setValue( "/qgis/measure/displayunits", QgsUnitTypes::encodeUnit( QGis::Meters ) );
|
||||
}
|
||||
//measurement settings
|
||||
|
||||
QGis::UnitType distanceUnit = static_cast< QGis::UnitType >( mDistanceUnitsComboBox->itemData( mDistanceUnitsComboBox->currentIndex() ).toInt() );
|
||||
mSettings->setValue( "/qgis/measure/displayunits", QgsUnitTypes::encodeUnit( distanceUnit ) );
|
||||
|
||||
QgsUnitTypes::AreaUnit areaUnit = static_cast< QgsUnitTypes::AreaUnit >( mAreaUnitsComboBox->itemData( mAreaUnitsComboBox->currentIndex() ).toInt() );
|
||||
mSettings->setValue( "/qgis/measure/areaunits", QgsUnitTypes::encodeUnit( areaUnit ) );
|
||||
|
||||
QString angleUnitString = "degrees";
|
||||
if ( mRadiansRadioButton->isChecked() )
|
||||
{
|
||||
angleUnitString = "radians";
|
||||
}
|
||||
else if ( mGonRadioButton->isChecked() )
|
||||
{
|
||||
angleUnitString = "gon";
|
||||
}
|
||||
mSettings->setValue( "/qgis/measure/angleunits", angleUnitString );
|
||||
QgsUnitTypes::AngleUnit angleUnit = static_cast< QgsUnitTypes::AngleUnit >( mAngleUnitsComboBox->itemData( mAngleUnitsComboBox->currentIndex() ).toInt() );
|
||||
mSettings->setValue( "/qgis/measure/angleunits", QgsUnitTypes::encodeUnit( angleUnit ) );
|
||||
|
||||
int decimalPlaces = mDecimalPlacesSpinBox->value();
|
||||
mSettings->setValue( "/qgis/measure/decimalplaces", decimalPlaces );
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include "qgsunittypes.h"
|
||||
#include <QCoreApplication>
|
||||
#include <QLocale>
|
||||
|
||||
/***************************************************************************
|
||||
* This class is considered CRITICAL and any change MUST be accompanied with
|
||||
@ -698,6 +699,248 @@ QgsUnitTypes::AreaUnit QgsUnitTypes::distanceToAreaUnit( QGis::UnitType distance
|
||||
return UnknownAreaUnit;
|
||||
}
|
||||
|
||||
QString QgsUnitTypes::encodeUnit( QgsUnitTypes::AngleUnit unit )
|
||||
{
|
||||
switch ( unit )
|
||||
{
|
||||
case AngleDegrees:
|
||||
return "degrees";
|
||||
case Radians:
|
||||
return "radians";
|
||||
case Gon:
|
||||
return "gon";
|
||||
case MinutesOfArc:
|
||||
return "moa";
|
||||
case SecondsOfArc:
|
||||
return "soa";
|
||||
case Turn:
|
||||
return "tr";
|
||||
case UnknownAngleUnit:
|
||||
return "<unknown>";
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QgsUnitTypes::AngleUnit QgsUnitTypes::decodeAngleUnit( const QString& string, bool* ok )
|
||||
{
|
||||
QString normalized = string.trimmed().toLower();
|
||||
|
||||
if ( ok )
|
||||
*ok = true;
|
||||
|
||||
if ( normalized == encodeUnit( AngleDegrees ) )
|
||||
return AngleDegrees;
|
||||
if ( normalized == encodeUnit( Radians ) )
|
||||
return Radians;
|
||||
if ( normalized == encodeUnit( Gon ) )
|
||||
return Gon;
|
||||
if ( normalized == encodeUnit( MinutesOfArc ) )
|
||||
return MinutesOfArc;
|
||||
if ( normalized == encodeUnit( SecondsOfArc ) )
|
||||
return SecondsOfArc;
|
||||
if ( normalized == encodeUnit( Turn ) )
|
||||
return Turn;
|
||||
if ( normalized == encodeUnit( UnknownAngleUnit ) )
|
||||
return UnknownAngleUnit;
|
||||
if ( ok )
|
||||
*ok = false;
|
||||
|
||||
return UnknownAngleUnit;
|
||||
}
|
||||
|
||||
QString QgsUnitTypes::toString( QgsUnitTypes::AngleUnit unit )
|
||||
{
|
||||
switch ( unit )
|
||||
{
|
||||
case AngleDegrees:
|
||||
return QCoreApplication::translate( "QgsUnitTypes::AngleUnit", "degrees" );
|
||||
case Radians:
|
||||
return QCoreApplication::translate( "QgsUnitTypes::AngleUnit", "radians" );
|
||||
case Gon:
|
||||
return QCoreApplication::translate( "QgsUnitTypes::AngleUnit", "gon" );
|
||||
case MinutesOfArc:
|
||||
return QCoreApplication::translate( "QgsUnitTypes::AngleUnit", "minutes of arc" );
|
||||
case SecondsOfArc:
|
||||
return QCoreApplication::translate( "QgsUnitTypes::AngleUnit", "seconds of arc" );
|
||||
case Turn:
|
||||
return QCoreApplication::translate( "QgsUnitTypes::AngleUnit", "turns" );
|
||||
case UnknownAngleUnit:
|
||||
return QCoreApplication::translate( "QgsUnitTypes::AngleUnit", "<unknown>" );
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
double QgsUnitTypes::fromUnitToUnitFactor( QgsUnitTypes::AngleUnit fromUnit, QgsUnitTypes::AngleUnit toUnit )
|
||||
{
|
||||
// Calculate the conversion factor between the specified units
|
||||
if ( fromUnit != toUnit )
|
||||
{
|
||||
switch ( fromUnit )
|
||||
{
|
||||
case AngleDegrees:
|
||||
{
|
||||
switch ( toUnit )
|
||||
{
|
||||
case AngleDegrees:
|
||||
return 1.0;
|
||||
case Radians:
|
||||
return M_PI / 180.0;
|
||||
case Gon:
|
||||
return 400.0 / 360.0;
|
||||
case MinutesOfArc:
|
||||
return 60;
|
||||
case SecondsOfArc:
|
||||
return 3600;
|
||||
case Turn:
|
||||
return 1.0 / 360.0;
|
||||
case UnknownAngleUnit:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Radians:
|
||||
{
|
||||
switch ( toUnit )
|
||||
{
|
||||
case AngleDegrees:
|
||||
return 180.0 / M_PI;
|
||||
case Radians:
|
||||
return 1.0;
|
||||
case Gon:
|
||||
return 200.0 / M_PI;
|
||||
case MinutesOfArc:
|
||||
return 60 * 180.0 / M_PI;
|
||||
case SecondsOfArc:
|
||||
return 3600 * 180.0 / M_PI;
|
||||
case Turn:
|
||||
return 0.5 / M_PI;
|
||||
case UnknownAngleUnit:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Gon:
|
||||
{
|
||||
switch ( toUnit )
|
||||
{
|
||||
case AngleDegrees:
|
||||
return 360.0 / 400.0;
|
||||
case Radians:
|
||||
return M_PI / 200.0;
|
||||
case Gon:
|
||||
return 1.0;
|
||||
case MinutesOfArc:
|
||||
return 60 * 360.0 / 400.0;
|
||||
case SecondsOfArc:
|
||||
return 3600 * 360.0 / 400.0;
|
||||
case Turn:
|
||||
return 1.0 / 400.0;
|
||||
case UnknownAngleUnit:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MinutesOfArc:
|
||||
{
|
||||
switch ( toUnit )
|
||||
{
|
||||
case AngleDegrees:
|
||||
return 1 / 60.0;
|
||||
case Radians:
|
||||
return M_PI / 180.0 / 60.0;
|
||||
case Gon:
|
||||
return 400.0 / 360.0 / 60.0;
|
||||
case MinutesOfArc:
|
||||
return 1.0;
|
||||
case SecondsOfArc:
|
||||
return 60.0;
|
||||
case Turn:
|
||||
return 1.0 / 360.0 / 60.0;
|
||||
case UnknownAngleUnit:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SecondsOfArc:
|
||||
{
|
||||
switch ( toUnit )
|
||||
{
|
||||
case AngleDegrees:
|
||||
return 1 / 3600.0;
|
||||
case Radians:
|
||||
return M_PI / 180.0 / 3600.0;
|
||||
case Gon:
|
||||
return 400.0 / 360.0 / 3600.0;
|
||||
case MinutesOfArc:
|
||||
return 1.0 / 60.0;
|
||||
case SecondsOfArc:
|
||||
return 1.0;
|
||||
case Turn:
|
||||
return 1.0 / 360.0 / 3600.0;
|
||||
case UnknownAngleUnit:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Turn:
|
||||
{
|
||||
switch ( toUnit )
|
||||
{
|
||||
case AngleDegrees:
|
||||
return 360.0;
|
||||
case Radians:
|
||||
return 2 * M_PI;
|
||||
case Gon:
|
||||
return 400.0;
|
||||
case MinutesOfArc:
|
||||
return 360.0 * 60.0;
|
||||
case SecondsOfArc:
|
||||
return 360.0 * 3600.0;
|
||||
case Turn:
|
||||
return 1.0;
|
||||
case UnknownAngleUnit:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case UnknownAngleUnit:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
QString QgsUnitTypes::formatAngle( double angle, int decimals, QgsUnitTypes::AngleUnit unit )
|
||||
{
|
||||
QString unitLabel;
|
||||
|
||||
switch ( unit )
|
||||
{
|
||||
case AngleDegrees:
|
||||
unitLabel = QObject::trUtf8( "°" );
|
||||
break;
|
||||
case Radians:
|
||||
unitLabel = QObject::trUtf8( " rad" );
|
||||
break;
|
||||
case Gon:
|
||||
unitLabel = QObject::trUtf8( " gon" );
|
||||
break;
|
||||
case MinutesOfArc:
|
||||
unitLabel = QObject::trUtf8( "′" );
|
||||
break;
|
||||
case SecondsOfArc:
|
||||
unitLabel = QObject::trUtf8( "″" );
|
||||
break;
|
||||
case Turn:
|
||||
unitLabel = QObject::trUtf8( " tr" );
|
||||
break;
|
||||
case UnknownAngleUnit:
|
||||
break;
|
||||
}
|
||||
|
||||
return QLocale::system().toString( angle, 'f', decimals ) + unitLabel;
|
||||
}
|
||||
|
||||
// enable for QGIS 3.0
|
||||
#if 0
|
||||
|
||||
|
@ -60,6 +60,18 @@ class CORE_EXPORT QgsUnitTypes
|
||||
UnknownAreaUnit, /*!< 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 */
|
||||
};
|
||||
|
||||
// DISTANCE UNITS
|
||||
|
||||
/** Returns the type for a distance unit.
|
||||
@ -148,6 +160,43 @@ class CORE_EXPORT QgsUnitTypes
|
||||
*/
|
||||
static AreaUnit distanceToAreaUnit( QGis::UnitType distanceUnit );
|
||||
|
||||
// ANGULAR UNITS
|
||||
|
||||
/** Encodes an angular unit to a string.
|
||||
* @param unit unit to encode
|
||||
* @returns encoded string
|
||||
* @see decodeAngleUnit()
|
||||
*/
|
||||
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 );
|
||||
|
||||
/** Returns a translated string representing an angular unit.
|
||||
* @param unit unit to convert to string
|
||||
*/
|
||||
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 );
|
||||
|
||||
/** 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 );
|
||||
|
||||
//TODO QGIS 3.0 - enable and move symbol units here! Otherwise creates circular dependancies...
|
||||
#if 0
|
||||
// SYMBOL UNITS
|
||||
|
@ -337,7 +337,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>949</width>
|
||||
<width>723</width>
|
||||
<height>670</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -1010,7 +1010,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>949</width>
|
||||
<width>663</width>
|
||||
<height>1057</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -1447,7 +1447,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>949</width>
|
||||
<width>581</width>
|
||||
<height>691</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -1826,7 +1826,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>949</width>
|
||||
<width>747</width>
|
||||
<height>802</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -2546,8 +2546,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>965</width>
|
||||
<height>578</height>
|
||||
<width>171</width>
|
||||
<height>258</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_46">
|
||||
@ -2651,8 +2651,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>965</width>
|
||||
<height>578</height>
|
||||
<width>528</width>
|
||||
<height>327</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_25">
|
||||
@ -2990,7 +2990,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>949</width>
|
||||
<height>635</height>
|
||||
<height>645</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_30">
|
||||
@ -3141,45 +3141,84 @@
|
||||
<string>Measure tool</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_21">
|
||||
<item row="5" column="3">
|
||||
<widget class="QRadioButton" name="radNautical">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="textLabel1_11">
|
||||
<property name="text">
|
||||
<string>Nautical Miles</string>
|
||||
<string>Preferred distance units</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QRadioButton" name="mDegreesRadioButton">
|
||||
<item row="4" column="1" colspan="3">
|
||||
<widget class="QComboBox" name="mAreaUnitsComboBox"/>
|
||||
</item>
|
||||
<item row="3" column="1" colspan="3">
|
||||
<widget class="QComboBox" name="mDistanceUnitsComboBox"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_13">
|
||||
<property name="toolTip">
|
||||
<string>If unchecked large numbers will be converted from m. to km. and from ft. to miles</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Degrees</string>
|
||||
<string>Keep base unit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="4">
|
||||
<widget class="QRadioButton" name="radDegrees">
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="mDecimalPlacesSpinBox"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_12">
|
||||
<property name="text">
|
||||
<string>Degrees</string>
|
||||
<string>Decimal places</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="2">
|
||||
<widget class="QRadioButton" name="mRadiansRadioButton">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="textLabel1_10">
|
||||
<property name="text">
|
||||
<string>Radians</string>
|
||||
<string>Rubberband color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<item row="0" column="2" colspan="2">
|
||||
<spacer>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>191</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="textLabel1_14">
|
||||
<property name="text">
|
||||
<string>Preferred area units</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QCheckBox" name="mKeepBaseUnitCheckBox">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="mAngleUnitsLabel">
|
||||
<property name="text">
|
||||
<string>Preferred angle units</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QSpinBox" name="mDecimalPlacesSpinBox"/>
|
||||
<item row="5" column="1" colspan="3">
|
||||
<widget class="QComboBox" name="mAngleUnitsComboBox"/>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="0" column="1">
|
||||
<widget class="QgsColorButtonV2" name="pbnMeasureColor">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
@ -3204,88 +3243,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QRadioButton" name="radMeters">
|
||||
<property name="text">
|
||||
<string>&Meters</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="2">
|
||||
<widget class="QRadioButton" name="radFeet">
|
||||
<property name="text">
|
||||
<string>Feet</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_13">
|
||||
<property name="toolTip">
|
||||
<string>If unchecked large numbers will be converted from m. to km. and from ft. to miles</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Keep base unit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="3">
|
||||
<widget class="QRadioButton" name="mGonRadioButton">
|
||||
<property name="text">
|
||||
<string>Gon</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="textLabel1_10">
|
||||
<property name="text">
|
||||
<string>Rubberband color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="textLabel1_11">
|
||||
<property name="text">
|
||||
<string>Preferred measurements units</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2" colspan="3">
|
||||
<spacer>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>191</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_12">
|
||||
<property name="text">
|
||||
<string>Decimal places</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QCheckBox" name="mKeepBaseUnitCheckBox">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="textLabel1_14">
|
||||
<property name="text">
|
||||
<string>Preferred area units</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1" colspan="4">
|
||||
<widget class="QComboBox" name="mAreaUnitsComboBox"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@ -5376,14 +5333,9 @@
|
||||
<tabstop>pbnMeasureColor</tabstop>
|
||||
<tabstop>mDecimalPlacesSpinBox</tabstop>
|
||||
<tabstop>mKeepBaseUnitCheckBox</tabstop>
|
||||
<tabstop>radMeters</tabstop>
|
||||
<tabstop>radFeet</tabstop>
|
||||
<tabstop>radNautical</tabstop>
|
||||
<tabstop>radDegrees</tabstop>
|
||||
<tabstop>mDistanceUnitsComboBox</tabstop>
|
||||
<tabstop>mAreaUnitsComboBox</tabstop>
|
||||
<tabstop>mDegreesRadioButton</tabstop>
|
||||
<tabstop>mRadiansRadioButton</tabstop>
|
||||
<tabstop>mGonRadioButton</tabstop>
|
||||
<tabstop>mAngleUnitsComboBox</tabstop>
|
||||
<tabstop>cmbWheelAction</tabstop>
|
||||
<tabstop>spinZoomFactor</tabstop>
|
||||
<tabstop>mListGlobalScales</tabstop>
|
||||
@ -5463,6 +5415,7 @@
|
||||
<tabstop>mAddUrlPushButton</tabstop>
|
||||
<tabstop>mRemoveUrlPushButton</tabstop>
|
||||
<tabstop>mAdvancedSettingsEnableButton</tabstop>
|
||||
<tabstop>cbxCheckVersion</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../../images/images.qrc"/>
|
||||
|
@ -247,6 +247,86 @@ class TestQgsUnitTypes(unittest.TestCase):
|
||||
for t in expected.keys():
|
||||
self.assertEqual(QgsUnitTypes.distanceToAreaUnit(t), expected[t])
|
||||
|
||||
def testEncodeDecodeAngleUnits(self):
|
||||
"""Test encoding and decoding angle units"""
|
||||
units = [QgsUnitTypes.AngleDegrees,
|
||||
QgsUnitTypes.Radians,
|
||||
QgsUnitTypes.Gon,
|
||||
QgsUnitTypes.MinutesOfArc,
|
||||
QgsUnitTypes.SecondsOfArc,
|
||||
QgsUnitTypes.Turn,
|
||||
QgsUnitTypes.UnknownAngleUnit]
|
||||
|
||||
for u in units:
|
||||
res, ok = QgsUnitTypes.decodeAngleUnit(QgsUnitTypes.encodeUnit(u))
|
||||
assert ok, 'could not decode unit {}'.format(QgsUnitTypes.toString(u))
|
||||
self.assertEqual(res, u)
|
||||
|
||||
# Test decoding bad units
|
||||
res, ok = QgsUnitTypes.decodeAngleUnit('bad')
|
||||
self.assertFalse(ok)
|
||||
self.assertEqual(res, QgsUnitTypes.UnknownAngleUnit)
|
||||
|
||||
# Test that string is cleaned before decoding
|
||||
res, ok = QgsUnitTypes.decodeAngleUnit(' MoA ')
|
||||
assert ok
|
||||
self.assertEqual(res, QgsUnitTypes.MinutesOfArc)
|
||||
|
||||
def testAngleToString(self):
|
||||
"""Test converting angle unit to string"""
|
||||
units = [QgsUnitTypes.AngleDegrees,
|
||||
QgsUnitTypes.Radians,
|
||||
QgsUnitTypes.Gon,
|
||||
QgsUnitTypes.MinutesOfArc,
|
||||
QgsUnitTypes.SecondsOfArc,
|
||||
QgsUnitTypes.Turn,
|
||||
QgsUnitTypes.UnknownAngleUnit]
|
||||
|
||||
dupes = set()
|
||||
|
||||
# can't test result as it may be translated, so make sure it's non-empty and not a duplicate
|
||||
for u in units:
|
||||
s = QgsUnitTypes.toString(u)
|
||||
assert len(s) > 0
|
||||
self.assertFalse(s in dupes)
|
||||
dupes.add(s)
|
||||
|
||||
def testAngleFromUnitToUnitFactor(self):
|
||||
"""Test calculation of conversion factor between angular units"""
|
||||
|
||||
expected = {QgsUnitTypes.AngleDegrees: {QgsUnitTypes.AngleDegrees: 1.0, QgsUnitTypes.Radians: 0.0174533, QgsUnitTypes.Gon: 1.1111111, QgsUnitTypes.MinutesOfArc: 60, QgsUnitTypes.SecondsOfArc: 3600, QgsUnitTypes.Turn: 0.00277777777778},
|
||||
QgsUnitTypes.Radians: {QgsUnitTypes.AngleDegrees: 57.2957795, QgsUnitTypes.Radians: 1.0, QgsUnitTypes.Gon: 63.6619772, QgsUnitTypes.MinutesOfArc: 3437.7467708, QgsUnitTypes.SecondsOfArc: 206264.8062471, QgsUnitTypes.Turn: 0.159154943092},
|
||||
QgsUnitTypes.Gon: {QgsUnitTypes.AngleDegrees: 0.9000000, QgsUnitTypes.Radians: 0.015707968623450838802, QgsUnitTypes.Gon: 1.0, QgsUnitTypes.MinutesOfArc: 54.0000000, QgsUnitTypes.SecondsOfArc: 3240.0000000, QgsUnitTypes.Turn: 0.0025},
|
||||
QgsUnitTypes.MinutesOfArc: {QgsUnitTypes.AngleDegrees: 0.016666672633390722247, QgsUnitTypes.Radians: 0.00029088831280398030638, QgsUnitTypes.Gon: 0.018518525464057963154, QgsUnitTypes.MinutesOfArc: 1.0, QgsUnitTypes.SecondsOfArc: 60.0, QgsUnitTypes.Turn: 4.62962962962963e-05},
|
||||
QgsUnitTypes.SecondsOfArc: {QgsUnitTypes.AngleDegrees: 0.00027777787722304257169, QgsUnitTypes.Radians: 4.848138546730629518e-6, QgsUnitTypes.Gon: 0.0003086420910674814405, QgsUnitTypes.MinutesOfArc: 0.016666672633325253783, QgsUnitTypes.SecondsOfArc: 1.0, QgsUnitTypes.Turn: 7.71604938271605e-07},
|
||||
QgsUnitTypes.Turn: {QgsUnitTypes.AngleDegrees: 360.0, QgsUnitTypes.Radians: 6.2831853071795, QgsUnitTypes.Gon: 400.0, QgsUnitTypes.MinutesOfArc: 21600, QgsUnitTypes.SecondsOfArc: 1296000, QgsUnitTypes.Turn: 1}
|
||||
}
|
||||
|
||||
for from_unit in expected.keys():
|
||||
for to_unit in expected[from_unit].keys():
|
||||
expected_factor = expected[from_unit][to_unit]
|
||||
res = QgsUnitTypes.fromUnitToUnitFactor(from_unit, to_unit)
|
||||
self.assertAlmostEqual(res,
|
||||
expected_factor,
|
||||
msg='got {:.7f}, expected {:.7f} when converting from {} to {}'.format(res, expected_factor,
|
||||
QgsUnitTypes.toString(from_unit),
|
||||
QgsUnitTypes.toString(to_unit)))
|
||||
#test conversion to unknown units
|
||||
res = QgsUnitTypes.fromUnitToUnitFactor(from_unit, QgsUnitTypes.UnknownAngleUnit)
|
||||
self.assertAlmostEqual(res,
|
||||
1.0,
|
||||
msg='got {:.7f}, expected 1.0 when converting from {} to unknown units'.format(res, expected_factor,
|
||||
QgsUnitTypes.toString(from_unit)))
|
||||
|
||||
def testFormatAngle(self):
|
||||
"""Test formatting angles"""
|
||||
self.assertEqual(QgsUnitTypes.formatAngle(45, 3, QgsUnitTypes.AngleDegrees), u'45.000°')
|
||||
self.assertEqual(QgsUnitTypes.formatAngle(1, 2, QgsUnitTypes.Radians), '1.00 rad')
|
||||
self.assertEqual(QgsUnitTypes.formatAngle(1, 0, QgsUnitTypes.Gon), u'1 gon')
|
||||
self.assertEqual(QgsUnitTypes.formatAngle(1.11111111, 4, QgsUnitTypes.MinutesOfArc), u'1.1111′')
|
||||
self.assertEqual(QgsUnitTypes.formatAngle(1.99999999, 2, QgsUnitTypes.SecondsOfArc), u'2.00″')
|
||||
self.assertEqual(QgsUnitTypes.formatAngle(1, 2, QgsUnitTypes.Turn), u'1.00 tr')
|
||||
self.assertEqual(QgsUnitTypes.formatAngle(1, 2, QgsUnitTypes.UnknownAngleUnit), u'1.00')
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user