Skip to content

Commit

Permalink
Cleanup variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 4, 2022
1 parent fb438d8 commit 7959fce
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 36 deletions.
63 changes: 35 additions & 28 deletions src/app/gps/qgsappgpsdigitizing.cpp
Expand Up @@ -15,7 +15,6 @@

#include "qgsappgpsdigitizing.h"
#include "qgsrubberband.h"
#include "qgsappgpssettingsmenu.h"
#include "qgslinesymbol.h"
#include "qgssymbollayerutils.h"
#include "qgsgui.h"
Expand Down Expand Up @@ -92,31 +91,39 @@ void QgsAppGpsDigitizing::addVertex()

// we store the capture list in wgs84 and then transform to layer crs when
// calling close feature
const QgsPoint point = QgsPoint( mLastGpsPosition.x(), mLastGpsPosition.y(), mLastElevation );
mCaptureList.push_back( point );
const QgsPoint pointWgs84 = QgsPoint( mLastGpsPositionWgs84.x(), mLastGpsPositionWgs84.y(), mLastElevation );
mCaptureListWgs84.push_back( pointWgs84 );


// we store the rubber band points in map canvas CRS so transform to map crs
// potential problem with transform errors and wrong coordinates if map CRS is changed after points are stored - SLM
// should catch map CRS change and transform the points
QgsPointXY myPoint;
QgsPointXY mapPoint;
if ( mCanvas )
{
myPoint = mCanvasToWgs84Transform.transform( mLastGpsPosition, Qgis::TransformDirection::Reverse );
try
{
mapPoint = mCanvasToWgs84Transform.transform( mLastGpsPositionWgs84, Qgis::TransformDirection::Reverse );
}
catch ( QgsCsException & )
{
QgsDebugMsg( QStringLiteral( "Could not transform GPS location (%1, %2) to map CRS" ).arg( mLastGpsPositionWgs84.x() ).arg( mLastGpsPositionWgs84.y() ) );
return;
}
}
else
{
myPoint = mLastGpsPosition;
mapPoint = mLastGpsPositionWgs84;
}

mRubberBand->addPoint( myPoint );
mRubberBand->addPoint( mapPoint );
}

void QgsAppGpsDigitizing::resetFeature()
{
mBlockGpsStateChanged++;
createRubberBand(); //deletes existing rubberband
mCaptureList.clear();
mCaptureListWgs84.clear();
mBlockGpsStateChanged--;
}

Expand All @@ -126,12 +133,12 @@ void QgsAppGpsDigitizing::addFeature()
if ( !vlayer )
return;

if ( vlayer->geometryType() == QgsWkbTypes::LineGeometry && mCaptureList.size() < 2 )
if ( vlayer->geometryType() == QgsWkbTypes::LineGeometry && mCaptureListWgs84.size() < 2 )
{
QgisApp::instance()->messageBar()->pushWarning( tr( "Add Feature" ), tr( "Cannot close a line feature until it has at least two vertices." ) );
return;
}
else if ( vlayer->geometryType() == QgsWkbTypes::PolygonGeometry && mCaptureList.size() < 3 )
else if ( vlayer->geometryType() == QgsWkbTypes::PolygonGeometry && mCaptureListWgs84.size() < 3 )
{
QgisApp::instance()->messageBar()->pushWarning( tr( "Add Feature" ),
tr( "Cannot close a polygon feature until it has at least three vertices." ) );
Expand All @@ -150,7 +157,7 @@ void QgsAppGpsDigitizing::addFeature()
}
}

const QgsCoordinateTransform t( mWgs84CRS, vlayer->crs(), QgsProject::instance() );
const QgsCoordinateTransform wgs84ToLayerTransform( mWgs84CRS, vlayer->crs(), QgsProject::instance() );
const bool is3D = QgsWkbTypes::hasZ( vlayer->wkbType() );
switch ( vlayer->geometryType() )
{
Expand All @@ -159,13 +166,13 @@ void QgsAppGpsDigitizing::addFeature()
QgsFeature f;
try
{
const QgsPointXY pointXY = t.transform( mLastGpsPosition );
const QgsPointXY pointXYLayerCrs = wgs84ToLayerTransform.transform( mLastGpsPositionWgs84 );

QgsGeometry g;
if ( is3D )
g = QgsGeometry( new QgsPoint( pointXY.x(), pointXY.y(), mLastElevation ) );
g = QgsGeometry( new QgsPoint( pointXYLayerCrs.x(), pointXYLayerCrs.y(), mLastElevation ) );
else
g = QgsGeometry::fromPointXY( pointXY );
g = QgsGeometry::fromPointXY( pointXYLayerCrs );

if ( QgsWkbTypes::isMultiType( vlayer->wkbType() ) )
g.convertToMultiType();
Expand Down Expand Up @@ -209,17 +216,17 @@ void QgsAppGpsDigitizing::addFeature()
QgsFeature f;
QgsGeometry g;

std::unique_ptr<QgsLineString> ring( new QgsLineString( mCaptureList ) );
std::unique_ptr<QgsLineString> ringWgs84( new QgsLineString( mCaptureListWgs84 ) );
if ( ! is3D )
ring->dropZValue();
ringWgs84->dropZValue();

if ( vlayer->geometryType() == QgsWkbTypes::LineGeometry )
{

g = QgsGeometry( ring.release() );
g = QgsGeometry( ringWgs84.release() );
try
{
g.transform( t );
g.transform( wgs84ToLayerTransform );
}
catch ( QgsCsException & )
{
Expand All @@ -232,14 +239,14 @@ void QgsAppGpsDigitizing::addFeature()
}
else if ( vlayer->geometryType() == QgsWkbTypes::PolygonGeometry )
{
ring->close();
ringWgs84->close();
std::unique_ptr<QgsPolygon> polygon( new QgsPolygon() );
polygon->setExteriorRing( ring.release() );
polygon->setExteriorRing( ringWgs84.release() );

g = QgsGeometry( polygon.release() );
try
{
g.transform( t );
g.transform( wgs84ToLayerTransform );
}
catch ( QgsCsException & )
{
Expand Down Expand Up @@ -292,7 +299,7 @@ void QgsAppGpsDigitizing::addFeature()
mRubberBand = nullptr;

// delete the elements of mCaptureList
mCaptureList.clear();
mCaptureListWgs84.clear();
} // action.addFeature()

mBlockGpsStateChanged--;
Expand Down Expand Up @@ -463,13 +470,13 @@ void QgsAppGpsDigitizing::gpsStateChanged( const QgsGpsInformation &info )
return;

const bool validFlag = info.isValid();
QgsPointXY myNewCenter;
QgsPointXY newLocationWgs84;
nmeaPOS newNmeaPosition;
nmeaTIME newNmeaTime;
double newAlt = 0.0;
if ( validFlag )
{
myNewCenter = QgsPointXY( info.longitude, info.latitude );
newLocationWgs84 = QgsPointXY( info.longitude, info.latitude );
newNmeaPosition.lat = nmea_degree2radian( info.latitude );
newNmeaPosition.lon = nmea_degree2radian( info.longitude );
newAlt = info.elevation;
Expand All @@ -478,14 +485,14 @@ void QgsAppGpsDigitizing::gpsStateChanged( const QgsGpsInformation &info )
}
else
{
myNewCenter = mLastGpsPosition;
newLocationWgs84 = mLastGpsPositionWgs84;
newNmeaPosition = mLastNmeaPosition;
newAlt = mLastElevation;
}
if ( !mAcquisitionEnabled || ( nmea_distance( &newNmeaPosition, &mLastNmeaPosition ) < mDistanceThreshold ) )
{
// do not update position if update is disabled by timer or distance is under threshold
myNewCenter = mLastGpsPosition;
newLocationWgs84 = mLastGpsPositionWgs84;

}
if ( validFlag && mAcquisitionEnabled )
Expand All @@ -495,9 +502,9 @@ void QgsAppGpsDigitizing::gpsStateChanged( const QgsGpsInformation &info )
}

// Avoid refreshing / panning if we haven't moved
if ( mLastGpsPosition != myNewCenter )
if ( mLastGpsPositionWgs84 != newLocationWgs84 )
{
mLastGpsPosition = myNewCenter;
mLastGpsPositionWgs84 = newLocationWgs84;
mLastNmeaPosition = newNmeaPosition;
mLastElevation = newAlt;

Expand Down
4 changes: 2 additions & 2 deletions src/app/gps/qgsappgpsdigitizing.h
Expand Up @@ -98,11 +98,11 @@ class APP_EXPORT QgsAppGpsDigitizing: public QObject
bool mAutoAddVertices = false;
bool mAutoSave = false;

QgsPointXY mLastGpsPosition;
QgsPointXY mLastGpsPositionWgs84;

QgsRubberBand *mRubberBand = nullptr;

QVector<QgsPoint> mCaptureList;
QVector<QgsPoint> mCaptureListWgs84;
double mLastElevation = 0.0;

nmeaPOS mLastNmeaPosition;
Expand Down
12 changes: 6 additions & 6 deletions tests/src/app/testqgsgpsintegration.cpp
Expand Up @@ -304,16 +304,16 @@ void TestQgsGpsIntegration::testTimestampWrite()
QCOMPARE( _testWrite( tempLayerString, gpsDigitizing, QStringLiteral( "stringf" ), Qt::TimeSpec::TimeZone ).toString( Qt::DateFormat::ISODate ), tzTime.toString( Qt::DateFormat::ISODate ) );

// Test write on line string field
gpsDigitizing.mCaptureList.push_back( QgsPoint( 1, 2 ) );
gpsDigitizing.mCaptureList.push_back( QgsPoint( 3, 4 ) );
gpsDigitizing.mCaptureListWgs84.push_back( QgsPoint( 1, 2 ) );
gpsDigitizing.mCaptureListWgs84.push_back( QgsPoint( 3, 4 ) );
QCOMPARE( _testWrite( tempLayerLineString, gpsDigitizing, QStringLiteral( "stringf" ), Qt::TimeSpec::UTC ).toString( Qt::DateFormat::ISODate ), dateTime.toString( Qt::DateFormat::ISODate ) );


gpsDigitizing.mCaptureList.push_back( QgsPoint( 1, 2 ) );
gpsDigitizing.mCaptureList.push_back( QgsPoint( 3, 4 ) );
gpsDigitizing.mCaptureListWgs84.push_back( QgsPoint( 1, 2 ) );
gpsDigitizing.mCaptureListWgs84.push_back( QgsPoint( 3, 4 ) );
QCOMPARE( _testWrite( tempLayerLineString, gpsDigitizing, QStringLiteral( "stringf" ), Qt::TimeSpec::LocalTime ).toString( Qt::DateFormat::ISODate ), localTime.toString( Qt::DateFormat::ISODate ) );
gpsDigitizing.mCaptureList.push_back( QgsPoint( 1, 2 ) );
gpsDigitizing.mCaptureList.push_back( QgsPoint( 3, 4 ) );
gpsDigitizing.mCaptureListWgs84.push_back( QgsPoint( 1, 2 ) );
gpsDigitizing.mCaptureListWgs84.push_back( QgsPoint( 3, 4 ) );
QCOMPARE( _testWrite( tempLayerLineString, gpsDigitizing, QStringLiteral( "stringf" ), Qt::TimeSpec::TimeZone ).toString( Qt::DateFormat::ISODate ), tzTime.toString( Qt::DateFormat::ISODate ) );

// Write on GPKG
Expand Down

0 comments on commit 7959fce

Please sign in to comment.