Index: src/app/qgsmeasuredialog.h =================================================================== --- src/app/qgsmeasuredialog.h (revision 14156) +++ src/app/qgsmeasuredialog.h (working copy) @@ -66,10 +66,10 @@ private: //! formats distance to most appropriate units - QString formatDistance( double distance ); + QString formatDistance( double distance, int decimalPlaces ); //! formats area to most appropriate units - QString formatArea( double area ); + QString formatArea( double area, int decimalPlaces ); //! shows/hides table, shows correct units void updateUi(); Index: src/app/qgsoptions.cpp =================================================================== --- src/app/qgsoptions.cpp (revision 14156) +++ src/app/qgsoptions.cpp (working copy) @@ -201,8 +201,24 @@ { mDegreesRadioButton->setChecked( true ); } - - + + // set decimal places of the measure tool + int decimalPlaces = settings.value("/qgis/measure/decimalplaces","3").toInt(); + mDecimalPlacesSpinBox->setRange(0,12); + mDecimalPlacesSpinBox->setValue( decimalPlaces ); + + // set if base unit of measure tool should be changed + bool baseUnit = settings.value("qgis/measure/keepbaseunit", false).toBool(); + if ( baseUnit == true ) + { + mKeepBaseUnitCheckBox->setChecked( true ); + } + else + { + mKeepBaseUnitCheckBox->setChecked( false ); + } + + // add the themes to the combo box on the option dialog QDir myThemeDir( ":/images/themes/" ); myThemeDir.setFilter( QDir::Dirs ); @@ -579,7 +595,15 @@ angleUnitString = "gon"; } settings.setValue( "/qgis/measure/angleunits", angleUnitString ); + + + int decimalPlaces = mDecimalPlacesSpinBox->value(); + settings.setValue( "/qgis/measure/decimalplaces", decimalPlaces ); + + bool baseUnit = mKeepBaseUnitCheckBox->isChecked(); + settings.setValue( "/qgis/measure/keepbaseunit", baseUnit ); + //set the color for selections QColor myColor = pbnSelectionColor->color(); settings.setValue( "/qgis/default_selection_color_red", myColor.red() ); Index: src/app/qgsmeasuredialog.cpp =================================================================== --- src/app/qgsmeasuredialog.cpp (revision 14156) +++ src/app/qgsmeasuredialog.cpp (working copy) @@ -50,6 +50,9 @@ mTable->addTopLevelItem( item ); //mTable->setHeaderLabels(QStringList() << tr("Segments (in meters)") << tr("Total") << tr("Azimuth") ); + + QSettings settings; + updateUi(); } @@ -85,6 +88,9 @@ void QgsMeasureDialog::mouseMove( QgsPoint &point ) { + QSettings settings; + int decimalPlaces = settings.value("/qgis/measure/decimalplaces","3").toInt(); + // show current distance/area while moving the point // by creating a temporary copy of point array // and adding moving point at the end @@ -93,29 +99,32 @@ QList tmpPoints = mTool->points(); tmpPoints.append( point ); double area = mTool->canvas()->mapRenderer()->distanceArea()->measurePolygon( tmpPoints ); - editTotal->setText( formatArea( area ) ); + editTotal->setText( formatArea( area, decimalPlaces ) ); } else if ( !mMeasureArea && mTool->points().size() > 0 ) { QgsPoint p1( mTool->points().last() ), p2( point ); double d = mTool->canvas()->mapRenderer()->distanceArea()->measureLine( p1, p2 ); - editTotal->setText( formatDistance( mTotal + d ) ); + editTotal->setText( formatDistance( mTotal + d, decimalPlaces ) ); QGis::UnitType myDisplayUnits; // Ignore units convertMeasurement( d, myDisplayUnits, false ); QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 ); - item->setText( 0, QLocale::system().toString( d, 'f', 2 ) ); + item->setText( 0, QLocale::system().toString( d, 'f', decimalPlaces ) ); } } void QgsMeasureDialog::addPoint( QgsPoint &point ) { + QSettings settings; + int decimalPlaces = settings.value("/qgis/measure/decimalplaces","3").toInt(); + int numPoints = mTool->points().size(); if ( mMeasureArea && numPoints > 2 ) { double area = mTool->canvas()->mapRenderer()->distanceArea()->measurePolygon( mTool->points() ); - editTotal->setText( formatArea( area ) ); + editTotal->setText( formatArea( area, decimalPlaces ) ); } else if ( !mMeasureArea && numPoints > 1 ) { @@ -126,16 +135,16 @@ double d = mTool->canvas()->mapRenderer()->distanceArea()->measureLine( p1, p2 ); mTotal += d; - editTotal->setText( formatDistance( mTotal ) ); + editTotal->setText( formatDistance( mTotal, decimalPlaces ) ); QGis::UnitType myDisplayUnits; // Ignore units convertMeasurement( d, myDisplayUnits, false ); QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 ); - item->setText( 0, QLocale::system().toString( d, 'f', 2 ) ); + item->setText( 0, QLocale::system().toString( d, 'f', decimalPlaces ) ); - item = new QTreeWidgetItem( QStringList( QLocale::system().toString( 0.0, 'f', 2 ) ) ); + item = new QTreeWidgetItem( QStringList( QLocale::system().toString( 0.0, 'f', decimalPlaces ) ) ); item->setTextAlignment( 0, Qt::AlignRight ); mTable->addTopLevelItem( item ); mTable->scrollToItem( item ); @@ -175,22 +184,90 @@ settings.setValue( key, height() ); } -QString QgsMeasureDialog::formatDistance( double distance ) +QString QgsMeasureDialog::formatDistance( double distance, int decimalPlaces ) { + QSettings settings; + bool baseUnit = settings.value("/qgis/measure/keepbaseunit", false).toBool(); + QGis::UnitType myDisplayUnits; convertMeasurement( distance, myDisplayUnits, false ); - return QgsDistanceArea::textUnit( distance, 2, myDisplayUnits, false ); + + if ( baseUnit == false ) + { + return QgsDistanceArea::textUnit( distance, decimalPlaces, myDisplayUnits, false ); + } + else + { + QString unitLabel; + + switch ( myDisplayUnits ) + { + case QGis::Meters: + unitLabel = " m"; + break; + case QGis::Feet: + if ( fabs( distance ) == 1.0 ) + unitLabel = QObject::tr( " foot" ); + else + unitLabel = QObject::tr( " feet" ); + break; + case QGis::Degrees: + if ( fabs( distance ) == 1.0 ) + unitLabel = QObject::tr( " degree" ); + else + unitLabel = QObject::tr( " degrees" ); + break; + case QGis::UnknownUnit: + unitLabel = QObject::tr( " unknown" ); + break; + } + + return QLocale::system().toString( distance, 'f', decimalPlaces ) + unitLabel; + } + } -QString QgsMeasureDialog::formatArea( double area ) +QString QgsMeasureDialog::formatArea( double area, int decimalPlaces ) { + QSettings settings; + bool baseUnit = settings.value("/qgis/measure/keepbaseunit", false).toBool(); + QGis::UnitType myDisplayUnits; convertMeasurement( area, myDisplayUnits, true ); - return QgsDistanceArea::textUnit( area, 2, myDisplayUnits, true ); + + if ( baseUnit == false ) + { + return QgsDistanceArea::textUnit( area, decimalPlaces, myDisplayUnits, true ); + } + else + { + QString unitLabel; + + switch ( myDisplayUnits ) + { + case QGis::Meters: + unitLabel = " m2"; + break; + case QGis::Feet: + unitLabel = QObject::tr( " sq ft" ); + break; + case QGis::Degrees: + unitLabel = QObject::tr( " sq.deg." ); + break; + case QGis::UnknownUnit: + unitLabel = QObject::tr( " unknown" ); + break; + } + return QLocale::system().toString( area, 'f', decimalPlaces ) + unitLabel; + } + } void QgsMeasureDialog::updateUi() { + QSettings settings; + int decimalPlaces = settings.value("/qgis/measure/decimalplaces","3").toInt(); + double dummy = 1.0; QGis::UnitType myDisplayUnits; // The dummy distance is ignored @@ -216,12 +293,12 @@ if ( mMeasureArea ) { mTable->hide(); - editTotal->setText( formatArea( 0 ) ); + editTotal->setText( formatArea( 0, decimalPlaces ) ); } else { mTable->show(); - editTotal->setText( formatDistance( 0 ) ); + editTotal->setText( formatDistance( 0, decimalPlaces ) ); } } Index: src/ui/qgsoptionsbase.ui =================================================================== --- src/ui/qgsoptionsbase.ui (revision 14156) +++ src/ui/qgsoptionsbase.ui (working copy) @@ -7,7 +7,7 @@ 0 0 813 - 605 + 622 @@ -215,7 +215,7 @@ - 0 + 2 @@ -696,24 +696,24 @@ Measure tool - + Ellipsoid for distance calculations - + - + Rubberband color - + @@ -726,7 +726,7 @@ - + Qt::Horizontal @@ -739,55 +739,79 @@ - + Preferred measurements units - + Meters - + Feet - + Preferred angle units - + Degrees - + Radians - + Gon + + + + Decimal places + + + + + + + + + + Keep base unit + + + + + + + + + +