Skip to content
Permalink
Browse files

fix measurement dialog translation (fixes #12262)

  • Loading branch information
jef-n committed Feb 26, 2015
1 parent c1773d8 commit 919b8b6183e3d0ec6df160f040cfaeb5d2964b87
Showing with 27 additions and 12 deletions.
  1. +2 −0 python/core/qgis.sip
  2. +8 −9 src/app/qgsmeasuredialog.cpp
  3. +12 −0 src/core/qgis.cpp
  4. +2 −0 src/core/qgis.h
  5. +1 −2 src/core/qgsdistancearea.cpp
  6. +2 −1 src/core/qgssnappingutils.cpp
@@ -129,6 +129,8 @@ class QGis
static UnitType fromLiteral( QString literal, QGis::UnitType defaultType = UnknownUnit );
//! Provides translated version of the type value
static QString tr( QGis::UnitType unit );
//! Provides type value from translated version
static UnitType fromTr( QString literal, QGis::UnitType defaultType = UnknownUnit );
//! Returns the conversion factor between the specified units
static double fromUnitToUnitFactor( QGis::UnitType fromUnit, QGis::UnitType toUnit );

@@ -43,14 +43,14 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool* tool, Qt::WindowFlags f )
mMeasureArea = tool->measureArea();
mTotal = 0.;

mUnitsCombo->addItem( tr( "Meters" ) );
mUnitsCombo->addItem( tr( "Feet" ) );
mUnitsCombo->addItem( tr( "Degrees" ) );
mUnitsCombo->addItem( tr( "Nautical Miles" ) );
mUnitsCombo->addItem( QGis::tr( QGis::Meters ) );
mUnitsCombo->addItem( QGis::tr( QGis::Feet ) );
mUnitsCombo->addItem( QGis::tr( QGis::Degrees ) );
mUnitsCombo->addItem( QGis::tr( QGis::NauticalMiles ) );

QSettings settings;
QString units = settings.value( "/qgis/measure/displayunits", "meters" ).toString();
mUnitsCombo->setCurrentIndex( mUnitsCombo->findText( units, Qt::MatchFixedString ) );
QString units = settings.value( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) ).toString();
mUnitsCombo->setCurrentIndex( mUnitsCombo->findText( QGis::tr( QGis::fromLiteral( units ) ), Qt::MatchFixedString ) );

updateSettings();

@@ -66,7 +66,7 @@ void QgsMeasureDialog::updateSettings()
mDecimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();
mCanvasUnits = mTool->canvas()->mapUnits();
// Configure QgsDistanceArea
mDisplayUnits = QGis::fromLiteral( mUnitsCombo->currentText().toLower() );
mDisplayUnits = QGis::fromTr( mUnitsCombo->currentText() );
mDa.setSourceCrs( mTool->canvas()->mapSettings().destinationCrs().srsid() );
mDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
// Only use ellipsoidal calculation when project wide transformation is enabled.
@@ -92,7 +92,7 @@ void QgsMeasureDialog::updateSettings()

void QgsMeasureDialog::unitsChanged( const QString &units )
{
mDisplayUnits = QGis::fromLiteral( units.toLower() );
mDisplayUnits = QGis::fromTr( units );
mTable->clear();
mTotal = 0.;
updateUi();
@@ -350,4 +350,3 @@ void QgsMeasureDialog::convertMeasurement( double &measure, QGis::UnitType &u, b
mDa.convertMeasurement( measure, myUnits, mDisplayUnits, isArea );
u = myUnits;
}

@@ -120,6 +120,18 @@ QString QGis::tr( QGis::UnitType unit )
return QCoreApplication::translate( "QGis::UnitType", qPrintable( toLiteral( unit ) ) );
}

QGis::UnitType QGis::fromTr( QString literal, QGis::UnitType defaultType )
{
for ( unsigned int i = 0; i < ( sizeof( qgisUnitTypes ) / sizeof( qgisUnitTypes[0] ) ); i++ )
{
if ( literal == QGis::tr( static_cast<UnitType>( i ) ) )
{
return static_cast<UnitType>( i );
}
}
return defaultType;
}

double QGis::fromUnitToUnitFactor( QGis::UnitType fromUnit, QGis::UnitType toUnit )
{
#define DEGREE_TO_METER 111319.49079327358
@@ -246,6 +246,8 @@ class CORE_EXPORT QGis
static UnitType fromLiteral( QString literal, QGis::UnitType defaultType = UnknownUnit );
//! Provides translated version of the type value
static QString tr( QGis::UnitType unit );
//! Provides type value from translated version
static UnitType fromTr( QString literal, QGis::UnitType defaultType = UnknownUnit );
//! Returns the conversion factor between the specified units
static double fromUnitToUnitFactor( QGis::UnitType fromUnit, QGis::UnitType toUnit );

@@ -1026,8 +1026,7 @@ QString QgsDistanceArea::textUnit( double value, int decimals, QGis::UnitType u,
//intentional fall-through
default:
QgsDebugMsg( QString( "Error: not picked up map units - actual value = %1" ).arg( u ) );
};

}

return QLocale::system().toString( value, 'f', decimals ) + unitLabel;
}
@@ -206,7 +206,8 @@ QgsPointLocator::Match QgsSnappingUtils::snapToMap( const QPoint& point, QgsPoin

QgsPointLocator::Match QgsSnappingUtils::snapToMap( const QgsPoint& pointMap, QgsPointLocator::MatchFilter* filter )
{
Q_ASSERT( mMapSettings.hasValidSettings() );
if ( !mMapSettings.hasValidSettings() )
return QgsPointLocator::Match();

if ( mSnapToMapMode == SnapCurrentLayer )
{

0 comments on commit 919b8b6

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