Index: src/app/qgsmeasuredialog.h =================================================================== --- src/app/qgsmeasuredialog.h (revision 14737) +++ src/app/qgsmeasuredialog.h (working copy) @@ -62,6 +62,9 @@ //! Show the help for the dialog void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); } + private slots: + //! on change state projection enable + void changeStateProjectionEnable(); private: Index: src/app/qgsdisplayangle.h =================================================================== --- src/app/qgsdisplayangle.h (revision 14737) +++ src/app/qgsdisplayangle.h (working copy) @@ -29,6 +29,15 @@ /**Sets the measured angle value (in radians). The value is going to be converted to degrees / gon automatically if necessary*/ void setValueInRadians( double value ); + + bool projectionEnabled(); + + signals: + void changeStateProjectionEnable(); + + private slots: + void changeState(); + }; #endif // QGSDISPLAYANGLE_H Index: src/app/qgsdisplayangle.cpp =================================================================== --- src/app/qgsdisplayangle.cpp (revision 14737) +++ src/app/qgsdisplayangle.cpp (working copy) @@ -20,6 +20,17 @@ QgsDisplayAngle::QgsDisplayAngle( QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f ) { setupUi( this ); + QSettings settings; + int s = settings.value( "/qgis/measure/projection_enable", "2" ).toInt(); + if ( s == 2 ) + mcbProjectionEnabled->setCheckState( Qt::Checked ); + else + mcbProjectionEnabled->setCheckState( Qt::Unchecked ); + + connect( mcbProjectionEnabled, SIGNAL( stateChanged(int) ), + this, SLOT( changeState() ) ); + connect( mcbProjectionEnabled, SIGNAL( stateChanged(int) ), + this, SIGNAL( changeStateProjectionEnable() ) ); } QgsDisplayAngle::~QgsDisplayAngle() @@ -27,6 +38,11 @@ } +bool QgsDisplayAngle::projectionEnabled() +{ + return mcbProjectionEnabled->isChecked(); +} + void QgsDisplayAngle::setValueInRadians( double value ) { QSettings settings; @@ -45,3 +61,11 @@ } } +void QgsDisplayAngle::changeState() +{ + QSettings settings; + if ( mcbProjectionEnabled->isChecked() ) + settings.setValue( "/qgis/measure/projection_enable", 2); + else + settings.setValue( "/qgis/measure/projection_enable", 0); +} Index: src/app/qgsmeasuredialog.cpp =================================================================== --- src/app/qgsmeasuredialog.cpp (revision 14737) +++ src/app/qgsmeasuredialog.cpp (working copy) @@ -52,7 +52,14 @@ //mTable->setHeaderLabels(QStringList() << tr("Segments (in meters)") << tr("Total") << tr("Azimuth") ); QSettings settings; + int s = settings.value( "/qgis/measure/projection_enable", "2" ).toInt(); + if ( s == 2 ) + mcbProjectionEnabled->setCheckState( Qt::Checked ); + else + mcbProjectionEnabled->setCheckState( Qt::Unchecked ); + connect( mcbProjectionEnabled, SIGNAL( stateChanged(int) ), + this, SLOT( changeStateProjectionEnable() )); updateUi(); } @@ -91,21 +98,27 @@ QSettings settings; int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt(); + // Create QgsDistance Area for customization ProjectionEnabled setting + QgsDistanceArea myDa; + myDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationSrs().srsid() ); + myDa.setEllipsoid( mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() ); + myDa.setProjectionsEnabled( mcbProjectionEnabled->isChecked() ); + // show current distance/area while moving the point // by creating a temporary copy of point array - // and adding moving point at the end + // and adding moving point at the end if ( mMeasureArea && mTool->points().size() > 1 ) { QList tmpPoints = mTool->points(); tmpPoints.append( point ); - double area = mTool->canvas()->mapRenderer()->distanceArea()->measurePolygon( tmpPoints ); + double area = myDa.measurePolygon( tmpPoints ); 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 ); + double d = myDa.measureLine( p1, p2 ); editTotal->setText( formatDistance( mTotal + d, decimalPlaces ) ); QGis::UnitType myDisplayUnits; // Ignore units @@ -120,10 +133,16 @@ QSettings settings; int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt(); + // Create QgsDistance Area for customization ProjectionEnabled setting + QgsDistanceArea myDa; + myDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationSrs().srsid() ); + myDa.setEllipsoid( mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() ); + myDa.setProjectionsEnabled( mcbProjectionEnabled->isChecked() ); + int numPoints = mTool->points().size(); if ( mMeasureArea && numPoints > 2 ) { - double area = mTool->canvas()->mapRenderer()->distanceArea()->measurePolygon( mTool->points() ); + double area = myDa.measurePolygon( mTool->points() ); editTotal->setText( formatArea( area, decimalPlaces ) ); } else if ( !mMeasureArea && numPoints > 1 ) @@ -132,7 +151,7 @@ QgsPoint p1 = mTool->points()[last], p2 = mTool->points()[last+1]; - double d = mTool->canvas()->mapRenderer()->distanceArea()->measureLine( p1, p2 ); + double d = myDa.measureLine( p1, p2 ); mTotal += d; editTotal->setText( formatDistance( mTotal, decimalPlaces ) ); @@ -252,17 +271,17 @@ QGis::UnitType myUnits = mTool->canvas()->mapUnits(); if (( myUnits == QGis::Degrees || myUnits == QGis::Feet ) && mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() != "NONE" && - mTool->canvas()->mapRenderer()->distanceArea()->hasCrsTransformEnabled() ) + mcbProjectionEnabled->isChecked() ) { // Measuring on an ellipsoid returns meters, and so does using projections??? myUnits = QGis::Meters; QgsDebugMsg( "We're measuring on an ellipsoid or using projections, the system is returning 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" ) { @@ -289,3 +308,68 @@ u = myUnits; } + +void QgsMeasureDialog::changeStateProjectionEnable() +{ + // store value + QSettings settings; + if ( mcbProjectionEnabled->isChecked() ) + settings.setValue( "/qgis/measure/projection_enable", 2); + else + settings.setValue( "/qgis/measure/projection_enable", 0); + + // clear interface + mTable->clear(); + QTreeWidgetItem* item = new QTreeWidgetItem( QStringList( QString::number( 0, 'f', 1 ) ) ); + item->setTextAlignment( 0, Qt::AlignRight ); + mTable->addTopLevelItem( item ); + mTotal = 0; + updateUi(); + + int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt(); + + // create DistanceArea + QgsDistanceArea myDa; + myDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationSrs().srsid() ); + myDa.setEllipsoid( mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() ); + myDa.setProjectionsEnabled( mcbProjectionEnabled->isChecked() ); + + if ( mMeasureArea ) + { + double area = 0.0; + if ( mTool->points().size() > 1 ) + { + area = myDa.measurePolygon( mTool->points() ); + } + editTotal->setText( formatArea( area, decimalPlaces ) ); + }else + { + QList::const_iterator it; + bool b = true; // first point + + QgsPoint p1,p2; + + for (it=mTool->points().constBegin(); it != mTool->points().constEnd(); ++it) + { + p2 = *it; + if ( !b ) + { + double d = myDa.measureLine( p1, p2 ); + mTotal += d; + editTotal->setText( formatDistance( mTotal, decimalPlaces ) ); + QGis::UnitType myDisplayUnits; + + convertMeasurement( d, myDisplayUnits, false ); + + QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 ); + item->setText( 0, QLocale::system().toString( d, 'f', decimalPlaces ) ); + item = new QTreeWidgetItem( QStringList( QLocale::system().toString( 0.0, 'f', decimalPlaces ) ) ); + item->setTextAlignment( 0, Qt::AlignRight ); + mTable->addTopLevelItem( item ); + mTable->scrollToItem( item ); + } + p1 = p2; + b = false; + } + } +} Index: src/app/qgsmaptoolmeasureangle.h =================================================================== --- src/app/qgsmaptoolmeasureangle.h (revision 14737) +++ src/app/qgsmaptoolmeasureangle.h (working copy) @@ -59,6 +59,9 @@ /**Deletes the rubber band and the dialog*/ void stopMeasuring(); + /** recalculate angle if projection state changed*/ + void changeStateProjectionEnable(); + }; #endif // QGSMAPTOOLMEASUREANGLE_H Index: src/app/qgsmaptoolmeasureangle.cpp =================================================================== --- src/app/qgsmaptoolmeasureangle.cpp (revision 14737) +++ src/app/qgsmaptoolmeasureangle.cpp (working copy) @@ -49,8 +49,25 @@ QgsDistanceArea* distArea = mCanvas->mapRenderer()->distanceArea(); if ( distArea ) { - double azimutOne = distArea->bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) ); - double azimutTwo = distArea->bearing( mAnglePoints.at( 1 ), point ); + //show angle in dialog + if ( !mResultDisplay ) + { + mResultDisplay = new QgsDisplayAngle( mCanvas->topLevelWidget() ); + QObject::connect( mResultDisplay, SIGNAL( rejected() ), this, SLOT( stopMeasuring() ) ); + QObject::connect( mResultDisplay, SIGNAL( changeStateProjectionEnable() ), + this, SLOT( changeStateProjectionEnable() ) ); + mResultDisplay->move( e->pos() - QPoint( 100, 100 ) ); + } + mResultDisplay->show(); + + QgsDistanceArea myDa; + myDa.setSourceCrs( mCanvas->mapRenderer()->destinationSrs().srsid() ); + myDa.setEllipsoid( distArea->ellipsoid() ); + myDa.setProjectionsEnabled( mResultDisplay->projectionEnabled() ); + + //angle calculation + double azimutOne = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) ); + double azimutTwo = myDa.bearing( mAnglePoints.at( 1 ), point ); double resultAngle = azimutTwo - azimutOne; QgsDebugMsg( QString::number( qAbs( resultAngle ) ) ); QgsDebugMsg( QString::number( M_PI ) ); @@ -66,14 +83,6 @@ } } - //show angle in dialog - if ( !mResultDisplay ) - { - mResultDisplay = new QgsDisplayAngle( mCanvas->topLevelWidget() ); - QObject::connect( mResultDisplay, SIGNAL( rejected() ), this, SLOT( stopMeasuring() ) ); - mResultDisplay->move( e->pos() - QPoint( 100, 100 ) ); - } - mResultDisplay->show(); mResultDisplay->setValueInRadians( resultAngle ); } } @@ -145,5 +154,36 @@ } } +void QgsMapToolMeasureAngle::changeStateProjectionEnable() +{ + if ( mAnglePoints.size() != 3 ) + return; + if ( !mResultDisplay ) + return; + + QgsDistanceArea myDa; + myDa.setSourceCrs( mCanvas->mapRenderer()->destinationSrs().srsid() ); + myDa.setEllipsoid( mCanvas->mapRenderer()->distanceArea()->ellipsoid() ); + myDa.setProjectionsEnabled( mResultDisplay->projectionEnabled() ); + //angle calculation + double azimutOne = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) ); + double azimutTwo = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 2 ) ); + double resultAngle = azimutTwo - azimutOne; + QgsDebugMsg( QString::number( fabs( resultAngle ) ) ); + QgsDebugMsg( QString::number( M_PI ) ); + if ( fabs( resultAngle ) > M_PI ) + { + if ( resultAngle < 0 ) + { + resultAngle = M_PI + ( resultAngle + M_PI ); + } + else + { + resultAngle = -M_PI + ( resultAngle - M_PI ); + } + } + mResultDisplay->setValueInRadians( resultAngle ); +} + Index: src/ui/qgsmeasurebase.ui =================================================================== --- src/ui/qgsmeasurebase.ui (revision 14737) +++ src/ui/qgsmeasurebase.ui (working copy) @@ -31,7 +31,7 @@ 6 - + @@ -47,7 +47,7 @@ - + Qt::Horizontal @@ -63,7 +63,7 @@ - + Total @@ -73,7 +73,7 @@ - + QAbstractItemView::NoEditTriggers @@ -91,13 +91,20 @@ - + QDialogButtonBox::Close|QDialogButtonBox::Help + + + + Ellipsoidal (WGS84) + + + Index: src/ui/qgsdisplayanglebase.ui =================================================================== --- src/ui/qgsdisplayanglebase.ui (revision 14737) +++ src/ui/qgsdisplayanglebase.ui (working copy) @@ -6,22 +6,22 @@ 0 0 - 276 - 78 + 293 + 105 Angle - + true - + Qt::Horizontal @@ -34,7 +34,7 @@ - + Qt::Horizontal @@ -44,6 +44,13 @@ + + + + Ellipsoidal (WGS84) + + +