[QGIS Commit] r14191 - in trunk/qgis: python/core src/app src/core
src/ui
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sat Sep 4 09:08:17 EDT 2010
Author: mhugent
Date: 2010-09-04 13:08:17 +0000 (Sat, 04 Sep 2010)
New Revision: 14191
Modified:
trunk/qgis/python/core/qgsdistancearea.sip
trunk/qgis/src/app/qgsmeasuredialog.cpp
trunk/qgis/src/app/qgsmeasuredialog.h
trunk/qgis/src/app/qgsoptions.cpp
trunk/qgis/src/core/qgsdistancearea.cpp
trunk/qgis/src/core/qgsdistancearea.h
trunk/qgis/src/ui/qgsoptionsbase.ui
Log:
Apply patch #2936 (Units and decimal places of measure tools) from Stefan Ziegler with small modifications
Modified: trunk/qgis/python/core/qgsdistancearea.sip
===================================================================
--- trunk/qgis/python/core/qgsdistancearea.sip 2010-09-04 07:54:42 UTC (rev 14190)
+++ trunk/qgis/python/core/qgsdistancearea.sip 2010-09-04 13:08:17 UTC (rev 14191)
@@ -58,6 +58,6 @@
//! compute bearing - in radians
double bearing(const QgsPoint& p1, const QgsPoint& p2);
- static QString textUnit(double value, int decimals, QGis::UnitType u, bool isArea);
+ static QString textUnit( double value, int decimals, QGis::UnitType u, bool isArea, bool keepBaseUnit = false );
};
Modified: trunk/qgis/src/app/qgsmeasuredialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsmeasuredialog.cpp 2010-09-04 07:54:42 UTC (rev 14190)
+++ trunk/qgis/src/app/qgsmeasuredialog.cpp 2010-09-04 13:08:17 UTC (rev 14191)
@@ -51,6 +51,9 @@
//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<QgsPoint> 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,31 @@
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 );
+ return QgsDistanceArea::textUnit( distance, decimalPlaces, myDisplayUnits, false, baseUnit );
}
-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 );
+ return QgsDistanceArea::textUnit( area, decimalPlaces, myDisplayUnits, true, baseUnit );
}
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 +234,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 ) );
}
}
Modified: trunk/qgis/src/app/qgsmeasuredialog.h
===================================================================
--- trunk/qgis/src/app/qgsmeasuredialog.h 2010-09-04 07:54:42 UTC (rev 14190)
+++ trunk/qgis/src/app/qgsmeasuredialog.h 2010-09-04 13:08:17 UTC (rev 14191)
@@ -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();
Modified: trunk/qgis/src/app/qgsoptions.cpp
===================================================================
--- trunk/qgis/src/app/qgsoptions.cpp 2010-09-04 07:54:42 UTC (rev 14190)
+++ trunk/qgis/src/app/qgsoptions.cpp 2010-09-04 13:08:17 UTC (rev 14191)
@@ -202,7 +202,23 @@
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 );
@@ -580,6 +596,14 @@
}
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() );
Modified: trunk/qgis/src/core/qgsdistancearea.cpp
===================================================================
--- trunk/qgis/src/core/qgsdistancearea.cpp 2010-09-04 07:54:42 UTC (rev 14190)
+++ trunk/qgis/src/core/qgsdistancearea.cpp 2010-09-04 13:08:17 UTC (rev 14191)
@@ -668,7 +668,7 @@
return fabs( area ); // All areas are positive!
}
-QString QgsDistanceArea::textUnit( double value, int decimals, QGis::UnitType u, bool isArea )
+QString QgsDistanceArea::textUnit( double value, int decimals, QGis::UnitType u, bool isArea, bool keepBaseUnit )
{
QString unitLabel;
@@ -678,8 +678,12 @@
case QGis::Meters:
if ( isArea )
{
- if ( fabs( value ) > 1000000.0 )
+ if ( keepBaseUnit )
{
+ unitLabel = QObject::tr( " m2" );
+ }
+ else if ( fabs( value ) > 1000000.0 )
+ {
unitLabel = QObject::tr( " km2" );
value = value / 1000000.0;
}
@@ -695,11 +699,9 @@
}
else
{
- if ( fabs( value ) == 0.0 )
+ if ( keepBaseUnit || fabs( value ) == 0.0 )
{
- // Special case for pretty printing.
unitLabel = QObject::tr( " m" );
-
}
else if ( fabs( value ) > 1000.0 )
{
@@ -725,30 +727,34 @@
case QGis::Feet:
if ( isArea )
{
- if ( fabs( value ) > ( 528.0*528.0 ) )
+ if ( keepBaseUnit || fabs( value ) <= ( 528.0*528.0 ) )
{
- unitLabel = QObject::tr( " sq mile" );
- value = value / ( 5280.0 * 5280.0 );
+ unitLabel = QObject::tr( " sq ft" );
}
else
{
- unitLabel = QObject::tr( " sq ft" );
+ unitLabel = QObject::tr( " sq mile" );
+ value = value / ( 5280.0 * 5280.0 );
}
}
else
{
- if ( fabs( value ) > 528.0 )
+ if ( fabs( value ) <= 528.0 || keepBaseUnit )
{
- unitLabel = QObject::tr( " mile" );
- value = value / 5280.0;
- }
- else
- {
if ( fabs( value ) == 1.0 )
+ {
unitLabel = QObject::tr( " foot" );
+ }
else
+ {
unitLabel = QObject::tr( " feet" );
+ }
}
+ else
+ {
+ unitLabel = QObject::tr( " mile" );
+ value = value / 5280.0;
+ }
}
break;
case QGis::Degrees:
Modified: trunk/qgis/src/core/qgsdistancearea.h
===================================================================
--- trunk/qgis/src/core/qgsdistancearea.h 2010-09-04 07:54:42 UTC (rev 14190)
+++ trunk/qgis/src/core/qgsdistancearea.h 2010-09-04 13:08:17 UTC (rev 14191)
@@ -85,7 +85,7 @@
//! compute bearing - in radians
double bearing( const QgsPoint& p1, const QgsPoint& p2 );
- static QString textUnit( double value, int decimals, QGis::UnitType u, bool isArea );
+ static QString textUnit( double value, int decimals, QGis::UnitType u, bool isArea, bool keepBaseUnit = false );
protected:
Modified: trunk/qgis/src/ui/qgsoptionsbase.ui
===================================================================
--- trunk/qgis/src/ui/qgsoptionsbase.ui 2010-09-04 07:54:42 UTC (rev 14190)
+++ trunk/qgis/src/ui/qgsoptionsbase.ui 2010-09-04 13:08:17 UTC (rev 14191)
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>813</width>
- <height>605</height>
+ <height>622</height>
</rect>
</property>
<property name="windowTitle">
@@ -215,7 +215,7 @@
<item row="0" column="1">
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
- <number>0</number>
+ <number>2</number>
</property>
<widget class="QWidget" name="stackedWidgetPage1">
<layout class="QVBoxLayout" name="verticalLayout_10">
@@ -696,24 +696,24 @@
<string>Measure tool</string>
</property>
<layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0">
+ <item row="1" column="0">
<widget class="QLabel" name="textLabel1_8">
<property name="text">
<string>Ellipsoid for distance calculations</string>
</property>
</widget>
</item>
- <item row="0" column="1">
+ <item row="1" column="1">
<widget class="QComboBox" name="cmbEllipsoid"/>
</item>
- <item row="1" column="0">
+ <item row="2" column="0">
<widget class="QLabel" name="textLabel1_10">
<property name="text">
<string>Rubberband color</string>
</property>
</widget>
</item>
- <item row="1" column="1">
+ <item row="2" column="1">
<widget class="QgsColorButton" name="pbnMeasureColor">
<property name="minimumSize">
<size>
@@ -726,7 +726,7 @@
</property>
</widget>
</item>
- <item row="1" column="2" colspan="2">
+ <item row="2" column="2" colspan="2">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -739,55 +739,79 @@
</property>
</spacer>
</item>
- <item row="2" column="0">
+ <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="1">
+ <item row="5" column="1">
<widget class="QRadioButton" name="radMeters">
<property name="text">
<string>Meters</string>
</property>
</widget>
</item>
- <item row="2" column="2">
+ <item row="5" column="2">
<widget class="QRadioButton" name="radFeet">
<property name="text">
<string>Feet</string>
</property>
</widget>
</item>
- <item row="3" column="0">
+ <item row="6" column="0">
<widget class="QLabel" name="mAngleUnitsLabel">
<property name="text">
<string>Preferred angle units</string>
</property>
</widget>
</item>
- <item row="3" column="1">
+ <item row="6" column="1">
<widget class="QRadioButton" name="mDegreesRadioButton">
<property name="text">
<string>Degrees</string>
</property>
</widget>
</item>
- <item row="3" column="2">
+ <item row="6" column="2">
<widget class="QRadioButton" name="mRadiansRadioButton">
<property name="text">
<string>Radians</string>
</property>
</widget>
</item>
- <item row="3" column="3">
+ <item row="6" column="3">
<widget class="QRadioButton" name="mGonRadioButton">
<property name="text">
<string>Gon</string>
</property>
</widget>
</item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="label_12">
+ <property name="text">
+ <string>Decimal places</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QSpinBox" name="mDecimalPlacesSpinBox"/>
+ </item>
+ <item row="4" column="0">
+ <widget class="QLabel" name="label_13">
+ <property name="text">
+ <string>Keep base unit</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1">
+ <widget class="QCheckBox" name="mKeepBaseUnitCheckBox">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>
More information about the QGIS-commit
mailing list