Showing with 64 additions and 46 deletions.
  1. +19 −19 src/app/qgsmaptoolmeasureangle.cpp
  2. +5 −1 src/app/qgsmaptoolmeasureangle.h
  3. +12 −23 src/app/qgsmeasuredialog.cpp
  4. +3 −1 src/app/qgsmeasuredialog.h
  5. +25 −2 src/ui/qgswmssourceselectbase.ui
38 changes: 19 additions & 19 deletions src/app/qgsmaptoolmeasureangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,15 @@ void QgsMapToolMeasureAngle::canvasMoveEvent( QMouseEvent * e )
mRubberBand->movePoint( point );
if ( mAnglePoints.size() == 2 )
{
if ( !mResultDisplay )
if ( !mResultDisplay->isVisible() )
{
mResultDisplay = new QgsDisplayAngle( mCanvas->topLevelWidget() );
QObject::connect( mResultDisplay, SIGNAL( rejected() ), this, SLOT( stopMeasuring() ) );
QObject::connect( mResultDisplay, SIGNAL( changeProjectionEnabledState() ),
this, SLOT( changeProjectionEnabledState() ) );
mResultDisplay->move( e->pos() - QPoint( 100, 100 ) );
mResultDisplay->show();
}
mResultDisplay->show();

QgsDistanceArea myDa;
configureDistanceArea( myDa );

//angle calculation
double azimuthOne = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
double azimuthTwo = myDa.bearing( mAnglePoints.at( 1 ), point );
double azimuthOne = mDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
double azimuthTwo = mDa.bearing( mAnglePoints.at( 1 ), point );
double resultAngle = azimuthTwo - azimuthOne;
QgsDebugMsg( QString::number( qAbs( resultAngle ) ) );
QgsDebugMsg( QString::number( M_PI ) );
Expand Down Expand Up @@ -90,6 +83,14 @@ void QgsMapToolMeasureAngle::canvasReleaseEvent( QMouseEvent * e )

if ( mAnglePoints.size() < 1 )
{
if ( mResultDisplay == NULL )
{
mResultDisplay = new QgsDisplayAngle( mCanvas->topLevelWidget() );
QObject::connect( mResultDisplay, SIGNAL( rejected() ), this, SLOT( stopMeasuring() ) );
QObject::connect( mResultDisplay, SIGNAL( changeProjectionEnabledState() ),
this, SLOT( changeProjectionEnabledState() ) );
}
configureDistanceArea();
createRubberBand();
}

Expand Down Expand Up @@ -153,12 +154,11 @@ void QgsMapToolMeasureAngle::changeProjectionEnabledState()
if ( !mResultDisplay )
return;

QgsDistanceArea myDa;
configureDistanceArea( myDa );
configureDistanceArea();

//angle calculation
double azimuthOne = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
double azimuthTwo = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 2 ) );
double azimuthOne = mDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
double azimuthTwo = mDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 2 ) );
double resultAngle = azimuthTwo - azimuthOne;
QgsDebugMsg( QString::number( fabs( resultAngle ) ) );
QgsDebugMsg( QString::number( M_PI ) );
Expand All @@ -177,13 +177,13 @@ void QgsMapToolMeasureAngle::changeProjectionEnabledState()

}

void QgsMapToolMeasureAngle::configureDistanceArea( QgsDistanceArea& da )
void QgsMapToolMeasureAngle::configureDistanceArea()
{
QSettings settings;
QString ellipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
da.setSourceCrs( mCanvas->mapRenderer()->destinationCrs().srsid() );
da.setEllipsoid( ellipsoidId );
da.setProjectionsEnabled( mResultDisplay->projectionEnabled() );
mDa.setSourceCrs( mCanvas->mapRenderer()->destinationCrs().srsid() );
mDa.setEllipsoid( ellipsoidId );
mDa.setProjectionsEnabled( mResultDisplay->projectionEnabled() );
}


Expand Down
6 changes: 5 additions & 1 deletion src/app/qgsmaptoolmeasureangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "qgsmaptool.h"
#include "qgsmapcanvassnapper.h"
#include "qgspoint.h"
#include "qgsdistancearea.h"

class QgsDisplayAngle;
class QgsRubberBand;
Expand Down Expand Up @@ -55,6 +56,9 @@ class QgsMapToolMeasureAngle: public QgsMapTool
/**Snaps point to background layers*/
QgsPoint snapPoint( const QPoint& p );

/** tool for measuring */
QgsDistanceArea mDa;

private slots:
/**Deletes the rubber band and the dialog*/
void stopMeasuring();
Expand All @@ -63,7 +67,7 @@ class QgsMapToolMeasureAngle: public QgsMapTool
void changeProjectionEnabledState();

//! Configures distance area objects with ellipsoid / output crs
void configureDistanceArea( QgsDistanceArea& da );
void configureDistanceArea();

};

Expand Down
35 changes: 12 additions & 23 deletions src/app/qgsmeasuredialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,21 @@ void QgsMeasureDialog::mouseMove( QgsPoint &point )
QSettings settings;
int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();

// Create QgsDistance Area for customization ProjectionEnabled setting
QgsDistanceArea myDa;
configureDistanceArea( myDa );

// show current distance/area while moving the point
// by creating a temporary copy of point array
// and adding moving point at the end
if ( mMeasureArea && mTool->points().size() > 1 )
{
QList<QgsPoint> tmpPoints = mTool->points();
tmpPoints.append( point );
double area = myDa.measurePolygon( tmpPoints );
double area = mDa.measurePolygon( tmpPoints );
editTotal->setText( formatArea( area, decimalPlaces ) );
}
else if ( !mMeasureArea && mTool->points().size() > 0 )
{
QgsPoint p1( mTool->points().last() ), p2( point );

double d = myDa.measureLine( p1, p2 );
double d = mDa.measureLine( p1, p2 );
editTotal->setText( formatDistance( mTotal + d, decimalPlaces ) );
QGis::UnitType myDisplayUnits;
// Ignore units
Expand All @@ -131,14 +127,10 @@ void QgsMeasureDialog::addPoint( QgsPoint &point )
QSettings settings;
int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();

// Create QgsDistance Area for customization ProjectionEnabled setting
QgsDistanceArea myDa;
configureDistanceArea( myDa );

int numPoints = mTool->points().size();
if ( mMeasureArea && numPoints > 2 )
{
double area = myDa.measurePolygon( mTool->points() );
double area = mDa.measurePolygon( mTool->points() );
editTotal->setText( formatArea( area, decimalPlaces ) );
}
else if ( !mMeasureArea && numPoints > 1 )
Expand All @@ -147,7 +139,7 @@ void QgsMeasureDialog::addPoint( QgsPoint &point )

QgsPoint p1 = mTool->points()[last], p2 = mTool->points()[last+1];

double d = myDa.measureLine( p1, p2 );
double d = mDa.measureLine( p1, p2 );

mTotal += d;
editTotal->setText( formatDistance( mTotal, decimalPlaces ) );
Expand Down Expand Up @@ -244,7 +236,7 @@ void QgsMeasureDialog::updateUi()
break;
case QGis::UnknownUnit:
mTable->setHeaderLabels( QStringList( tr( "Segments" ) ) );
};
}

if ( mMeasureArea )
{
Expand All @@ -257,6 +249,7 @@ void QgsMeasureDialog::updateUi()
editTotal->setText( formatDistance( 0, decimalPlaces ) );
}

configureDistanceArea();
}

void QgsMeasureDialog::convertMeasurement( double &measure, QGis::UnitType &u, bool isArea )
Expand Down Expand Up @@ -323,16 +316,12 @@ void QgsMeasureDialog::changeProjectionEnabledState()

int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();

// create DistanceArea
QgsDistanceArea myDa;
configureDistanceArea( myDa );

if ( mMeasureArea )
{
double area = 0.0;
if ( mTool->points().size() > 1 )
{
area = myDa.measurePolygon( mTool->points() );
area = mDa.measurePolygon( mTool->points() );
}
editTotal->setText( formatArea( area, decimalPlaces ) );
}
Expand All @@ -348,7 +337,7 @@ void QgsMeasureDialog::changeProjectionEnabledState()
p2 = *it;
if ( !b )
{
double d = myDa.measureLine( p1, p2 );
double d = mDa.measureLine( p1, p2 );
mTotal += d;
editTotal->setText( formatDistance( mTotal, decimalPlaces ) );
QGis::UnitType myDisplayUnits;
Expand All @@ -368,11 +357,11 @@ void QgsMeasureDialog::changeProjectionEnabledState()
}
}

void QgsMeasureDialog::configureDistanceArea( QgsDistanceArea& da )
void QgsMeasureDialog::configureDistanceArea()
{
QSettings settings;
QString ellipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
da.setSourceCrs( mTool->canvas()->mapRenderer()->destinationCrs().srsid() );
da.setEllipsoid( ellipsoidId );
da.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );
mDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationCrs().srsid() );
mDa.setEllipsoid( ellipsoidId );
mDa.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );
}
4 changes: 3 additions & 1 deletion src/app/qgsmeasuredialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ class QgsMeasureDialog : public QDialog, private Ui::QgsMeasureBase
void convertMeasurement( double &measure, QGis::UnitType &u, bool isArea );

//! Configures distance area objects with ellipsoid / output crs
void configureDistanceArea( QgsDistanceArea& da );
void configureDistanceArea();

double mTotal;

//! indicates whether we're measuring distances or areas
bool mMeasureArea;

QgsDistanceArea mDa;

//! pointer to measure tool which owns this dialog
QgsMeasureTool* mTool;
};
Expand Down
27 changes: 25 additions & 2 deletions src/ui/qgswmssourceselectbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,23 @@
</property>
</widget>
</item>
<item row="1" column="9">
<widget class="QPushButton" name="btnSave">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
<item row="1" column="8">
<widget class="QPushButton" name="btnLoad">
<property name="toolTip">
<string>Load connections from file</string>
</property>
<property name="text">
<string>Load</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="12">
<widget class="QGroupBox" name="gbCRS">
<property name="title">
Expand Down Expand Up @@ -252,15 +269,21 @@
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QPushButton" name="mLayerUpButton">
<property name="toolTip">
<string>Move selected layer UP</string>
</property>
<property name="text">
<string/>
<string>Up</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="mLayerDownButton">
<property name="toolTip">
<string>Move selected layer DOWN</string>
</property>
<property name="text">
<string/>
<string>Down</string>
</property>
</widget>
</item>
Expand Down