[QGIS Commit] r11340 - in trunk/qgis/src: app ui
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Mon Aug 10 18:22:40 EDT 2009
Author: homann
Date: 2009-08-10 18:22:40 -0400 (Mon, 10 Aug 2009)
New Revision: 11340
Modified:
trunk/qgis/src/app/qgisapp.cpp
trunk/qgis/src/app/qgsmeasuredialog.cpp
trunk/qgis/src/app/qgsmeasuredialog.h
trunk/qgis/src/app/qgsoptions.cpp
trunk/qgis/src/app/qgsprojectproperties.cpp
trunk/qgis/src/app/qgsprojectproperties.h
trunk/qgis/src/ui/qgsoptionsbase.ui
trunk/qgis/src/ui/qgsprojectpropertiesbase.ui
Log:
A stab at improving the measurement system. Added a new selector in Options for converting the result, and grayed out the layer units when OTFP is on. Should fix #1219, I hope.
Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp 2009-08-10 22:13:19 UTC (rev 11339)
+++ trunk/qgis/src/app/qgisapp.cpp 2009-08-10 22:22:40 UTC (rev 11340)
@@ -5435,7 +5435,9 @@
QApplication::restoreOverrideCursor();
//pass any refresg signals off to canvases
- //connect (pp,SIGNAL(refresh()), mMapCanvas, SLOT(refresh()));
+ // Line below was commented out by wonder three years ago (r4949).
+ // It is needed to refresh scale bar after changing display units.
+ connect (pp,SIGNAL(refresh()), mMapCanvas, SLOT(refresh()));
QgsMapRenderer* myRender = mMapCanvas->mapRenderer();
bool wasProjected = myRender->hasCrsTransformEnabled();
Modified: trunk/qgis/src/app/qgsmeasuredialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsmeasuredialog.cpp 2009-08-10 22:13:19 UTC (rev 11339)
+++ trunk/qgis/src/app/qgsmeasuredialog.cpp 2009-08-10 22:22:40 UTC (rev 11340)
@@ -18,6 +18,7 @@
#include "qgsmeasuredialog.h"
#include "qgsmeasuretool.h"
+#include "qgslogger.h"
#include "qgscontexthelp.h"
#include "qgsdistancearea.h"
#include "qgsmapcanvas.h"
@@ -89,6 +90,9 @@
QList<QgsPoint> tmpPoints = mTool->points();
tmpPoints.append( point );
double area = mTool->canvas()->mapRenderer()->distanceArea()->measurePolygon( tmpPoints );
+ QGis::UnitType myDisplayUnits;
+ // Ignore units
+ convertMeasurement( area, myDisplayUnits, true );
editTotal->setText( formatArea( area ) );
}
else if ( !mMeasureArea && mTool->points().size() > 0 )
@@ -96,9 +100,12 @@
QgsPoint p1( mTool->points().last() ), p2( point );
double d = mTool->canvas()->mapRenderer()->distanceArea()->measureLine( p1, p2 );
+ editTotal->setText( formatDistance( mTotal + d ) );
+ 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 ) );
- editTotal->setText( formatDistance( mTotal + d ) );
}
}
@@ -108,6 +115,9 @@
if ( mMeasureArea && numPoints > 2 )
{
double area = mTool->canvas()->mapRenderer()->distanceArea()->measurePolygon( mTool->points() );
+ QGis::UnitType myDisplayUnits;
+ // Ignore units
+ convertMeasurement( area, myDisplayUnits, true );
editTotal->setText( formatArea( area ) );
}
else if ( !mMeasureArea && numPoints > 1 )
@@ -121,6 +131,10 @@
mTotal += d;
editTotal->setText( formatDistance( mTotal ) );
+ 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 ) );
@@ -173,24 +187,26 @@
QString QgsMeasureDialog::formatDistance( double distance )
{
- QString txt;
- QString unitLabel;
-
- QGis::UnitType myMapUnits = mTool->canvas()->mapUnits();
- return QgsDistanceArea::textUnit( distance, 2, myMapUnits, false );
+ QGis::UnitType myDisplayUnits;
+ convertMeasurement( distance, myDisplayUnits, false );
+ return QgsDistanceArea::textUnit( distance, 2, myDisplayUnits, false );
}
QString QgsMeasureDialog::formatArea( double area )
{
- QGis::UnitType myMapUnits = mTool->canvas()->mapUnits();
- return QgsDistanceArea::textUnit( area, 2, myMapUnits, true );
+ QGis::UnitType myDisplayUnits;
+ convertMeasurement( area, myDisplayUnits, true );
+ return QgsDistanceArea::textUnit( area, 2, myDisplayUnits, true );
}
void QgsMeasureDialog::updateUi()
{
+ double dummy = 1.0;
+ QGis::UnitType myDisplayUnits;
+ // The dummy distance is ignored
+ convertMeasurement( dummy, myDisplayUnits, false );
- QGis::UnitType myMapUnits = mTool->canvas()->mapUnits();
- switch ( myMapUnits )
+ switch ( myDisplayUnits )
{
case QGis::Meters:
mTable->setHeaderLabels( QStringList( tr( "Segments (in meters)" ) ) );
@@ -218,3 +234,43 @@
}
+void QgsMeasureDialog::convertMeasurement(double &measure, QGis::UnitType &u, bool isArea)
+{
+ // Helper for converting between meters and feet
+ // The parameter &u is out only...
+
+ QGis::UnitType myUnits = mTool->canvas()->mapUnits();
+ if ( myUnits == QGis::Degrees &&
+ mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() != "NONE" &&
+ mTool->canvas()->mapRenderer()->distanceArea()->hasCrsTransformEnabled() )
+ {
+ // Measuring on an ellipsoid returns meters
+ myUnits = QGis::Meters;
+ }
+
+ // Get the units for display
+ QSettings settings;
+ QString myDisplayUnitsTxt = settings.value( "/qgis/measure/displayunits", "meters").toString();
+
+ // Only convert between meters and feet
+ if ( myUnits == QGis::Meters && myDisplayUnitsTxt == "feet" )
+ {
+ measure /= 0.3048;
+ if ( isArea )
+ {
+ measure /= 0.3048;
+ }
+ myUnits = QGis::Feet;
+ }
+ if ( myUnits == QGis::Feet && myDisplayUnitsTxt == "meters" )
+ {
+ measure *= 0.3048 * 0.3048;
+ if ( isArea )
+ {
+ measure *= 0.3048;
+ }
+ myUnits = QGis::Meters;
+ }
+
+ u = myUnits;
+}
Modified: trunk/qgis/src/app/qgsmeasuredialog.h
===================================================================
--- trunk/qgis/src/app/qgsmeasuredialog.h 2009-08-10 22:13:19 UTC (rev 11339)
+++ trunk/qgis/src/app/qgsmeasuredialog.h 2009-08-10 22:22:40 UTC (rev 11340)
@@ -20,6 +20,7 @@
#include "ui_qgsmeasurebase.h"
#include "qgspoint.h"
+#include "qgsdistancearea.h"
class QCloseEvent;
class QgsMeasureTool;
@@ -72,6 +73,9 @@
//! shows/hides table, shows correct units
void updateUi();
+ //! Converts the measurement, depending on settings in options and current transformation
+ void convertMeasurement(double &measure, QGis::UnitType &u, bool isArea);
+
double mTotal;
//! Help context id
Modified: trunk/qgis/src/app/qgsoptions.cpp
===================================================================
--- trunk/qgis/src/app/qgsoptions.cpp 2009-08-10 22:13:19 UTC (rev 11339)
+++ trunk/qgis/src/app/qgsoptions.cpp 2009-08-10 22:22:40 UTC (rev 11340)
@@ -113,6 +113,17 @@
getEllipsoidList();
QString myEllipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
cmbEllipsoid->setItemText( cmbEllipsoid->currentIndex(), getEllipsoidName( myEllipsoidId ) );
+
+ // Set the units for measuring
+ QString myUnitsTxt = settings.value( "/qgis/measure/displayunits", "meters").toString();
+ if ( myUnitsTxt == "feet" )
+ {
+ radFeet->setChecked( true );
+ } else {
+ radMeters->setChecked( true );
+ }
+
+
// add the themes to the combo box on the option dialog
QDir myThemeDir( QgsApplication::pkgDataPath() + "/themes/" );
myThemeDir.setFilter( QDir::Dirs );
@@ -402,6 +413,15 @@
settings.setValue( "/qgis/measure/ellipsoid", getEllipsoidAcronym( cmbEllipsoid->currentText() ) );
+ if ( radFeet->isChecked() )
+ {
+ settings.setValue( "/qgis/measure/displayunits", "feet" );
+ }
+ else
+ {
+ settings.setValue( "/qgis/measure/displayunits", "meters" );
+ }
+ settings.setValue( "/qgis/measure/ellipsoid", getEllipsoidAcronym( cmbEllipsoid->currentText() ) );
//set the colour for selections
QColor myColor = pbnSelectionColour->color();
settings.setValue( "/qgis/default_selection_color_red", myColor.red() );
Modified: trunk/qgis/src/app/qgsprojectproperties.cpp
===================================================================
--- trunk/qgis/src/app/qgsprojectproperties.cpp 2009-08-10 22:13:19 UTC (rev 11339)
+++ trunk/qgis/src/app/qgsprojectproperties.cpp 2009-08-10 22:22:40 UTC (rev 11340)
@@ -58,6 +58,7 @@
//see if the user wants on the fly projection enabled
bool myProjectionEnabled = myRender->hasCrsTransformEnabled();
cbxProjectionEnabled->setChecked( myProjectionEnabled );
+ btnGrpMapUnits->setEnabled( !myProjectionEnabled );
long myCRSID = myRender->destinationSrs().srsid();
QgsDebugMsg( "Read project CRSID: " + QString::number( myCRSID ) );
@@ -430,3 +431,9 @@
d.layerSettings( mSnappingLayerSettings );
}
}
+
+void QgsProjectProperties::on_cbxProjectionEnabled_stateChanged(int state)
+{
+ btnGrpMapUnits->setEnabled( state == Qt::Unchecked );
+}
+
Modified: trunk/qgis/src/app/qgsprojectproperties.h
===================================================================
--- trunk/qgis/src/app/qgsprojectproperties.h 2009-08-10 22:13:19 UTC (rev 11339)
+++ trunk/qgis/src/app/qgsprojectproperties.h 2009-08-10 22:22:40 UTC (rev 11340)
@@ -93,6 +93,9 @@
*/
void on_mSnappingOptionsPushButton_clicked();
+ void on_cbxProjectionEnabled_stateChanged(int state);
+
+
signals:
//! Signal used to inform listeners that the mouse display precision may have changed
void displayPrecisionChanged();
Modified: trunk/qgis/src/ui/qgsoptionsbase.ui
===================================================================
--- trunk/qgis/src/ui/qgsoptionsbase.ui 2009-08-10 22:13:19 UTC (rev 11339)
+++ trunk/qgis/src/ui/qgsoptionsbase.ui 2009-08-10 22:22:40 UTC (rev 11340)
@@ -476,6 +476,27 @@
</property>
</widget>
</item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="textLabel1_8">
+ <property name="text">
+ <string>Display units (if applicable)</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QRadioButton" name="radMeters">
+ <property name="text">
+ <string>Meters</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="2">
+ <widget class="QRadioButton" name="radFeet">
+ <property name="text">
+ <string>Feet</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>
Modified: trunk/qgis/src/ui/qgsprojectpropertiesbase.ui
===================================================================
--- trunk/qgis/src/ui/qgsprojectpropertiesbase.ui 2009-08-10 22:13:19 UTC (rev 11339)
+++ trunk/qgis/src/ui/qgsprojectpropertiesbase.ui 2009-08-10 22:22:40 UTC (rev 11340)
@@ -139,7 +139,7 @@
<item row="1" column="0">
<widget class="QGroupBox" name="btnGrpMapUnits">
<property name="title">
- <string>Map units</string>
+ <string>Layer units (only used when CRS transformation is disabled)</string>
</property>
<layout class="QHBoxLayout">
<property name="margin">
More information about the QGIS-commit
mailing list