Skip to content

Commit

Permalink
Remove redundant checks and apply recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Jun 24, 2019
1 parent 8a87a10 commit f220a7f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
28 changes: 14 additions & 14 deletions src/app/gps/qgsgpsinformationwidget.cpp
Expand Up @@ -87,8 +87,6 @@ QgsGpsInformationWidget::QgsGpsInformationWidget( QgsMapCanvas *mapCanvas, QWidg
connect( mBtnResetFeature, &QToolButton::clicked, this, &QgsGpsInformationWidget::mBtnResetFeature_clicked );
connect( mBtnLogFile, &QPushButton::clicked, this, &QgsGpsInformationWidget::mBtnLogFile_clicked );

mLastLayer = nullptr;

mLastGpsPosition = QgsPointXY( 0.0, 0.0 );
mLastNmeaPosition.lat = nmea_degree2radian( 0.0 );
mLastNmeaPosition.lon = nmea_degree2radian( 0.0 );
Expand Down Expand Up @@ -296,9 +294,9 @@ QgsGpsInformationWidget::QgsGpsInformationWidget( QgsMapCanvas *mapCanvas, QWidg
// Qt::UTC 1 Coordinated Universal Time, replaces Greenwich Mean Time.
// SKIP this one: Qt::OffsetFromUTC 2 An offset in seconds from Coordinated Universal Time.
// Qt::TimeZone 3 A named time zone using a specific set of Daylight Savings rules.
mCboTimestampFormat->addItem( tr( "Local time" ), Qt::TimeSpec::LocalTime );
mCboTimestampFormat->addItem( tr( "Local Time" ), Qt::TimeSpec::LocalTime );
mCboTimestampFormat->addItem( tr( "UTC" ), Qt::TimeSpec::UTC );
mCboTimestampFormat->addItem( tr( "Time zone" ), Qt::TimeSpec::TimeZone );
mCboTimestampFormat->addItem( tr( "Time Zone" ), Qt::TimeSpec::TimeZone );
mCboTimestampFormat->setCurrentIndex( mySettings.value( QStringLiteral( "gps/timeStampFormat" ), Qt::LocalTime ).toInt() );
connect( mCboTimestampFormat, qgis::overload< int >::of( &QComboBox::currentIndexChanged ),
this, &QgsGpsInformationWidget::timestampFormatChanged );
Expand Down Expand Up @@ -965,7 +963,7 @@ void QgsGpsInformationWidget::mBtnCloseFeature_clicked()
if ( idx != -1 )
{
QVariant ts { timestamp( vlayer, idx ) };
if ( ts.isValid() && idx != -1 )
if ( ts.isValid() )
{
attrMap[ idx ] = ts;
}
Expand Down Expand Up @@ -1127,7 +1125,8 @@ void QgsGpsInformationWidget::mBtnCloseFeature_clicked()
delete f;
connectGpsSlot();
} // layerWKBType == QgsWkbTypes::Point
mMapCanvas->refresh(); // NOTE: canceling feature add refreshes canvas, OK does not; this may change, however, so do it anyway

vlayer->triggerRepaint();

// force focus back to GPS window/ Add Feature button for ease of use by keyboard
activateWindow();
Expand Down Expand Up @@ -1329,7 +1328,7 @@ void QgsGpsInformationWidget::updateTimeZones()
QVariant QgsGpsInformationWidget::timestamp( QgsVectorLayer *vlayer, int idx )
{
QVariant value;
if ( idx != -1 && ! mCboTimestampField->currentText().isEmpty() )
if ( idx != -1 )
{
QDateTime time( QDate( 1900 + mLastNmeaTime.year, mLastNmeaTime.mon + 1, mLastNmeaTime.day ),
QTime( mLastNmeaTime.hour, mLastNmeaTime.min, mLastNmeaTime.sec, mLastNmeaTime.msec ) );
Expand Down Expand Up @@ -1361,16 +1360,17 @@ QVariant QgsGpsInformationWidget::timestamp( QgsVectorLayer *vlayer, int idx )
// Do nothing: we are already in UTC
}

if ( idx != -1 )
// Only string and datetime fields are supported
switch ( vlayer->fields().at( idx ).type() )
{
if ( vlayer->fields().at( idx ).type() == QVariant::String )
{
case QVariant::String:
value = time.toString( Qt::DateFormat::ISODate );
}
else // Datetime
{
break;
case QVariant::DateTime:
value = time;
}
break;
default:
break;
}
}
return value;
Expand Down
6 changes: 1 addition & 5 deletions src/app/gps/qgsgpsmarker.cpp
Expand Up @@ -30,10 +30,6 @@ QgsGpsMarker::QgsGpsMarker( QgsMapCanvas *mapCanvas )
mSize = 16;
mWgs84CRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( QStringLiteral( "EPSG:4326" ) );
mSvg.load( QStringLiteral( ":/images/north_arrows/gpsarrow2.svg" ) );
if ( ! mSvg.isValid() )
{
QgsMessageLog::logMessage( QObject::tr( "GPS marker not found!" ), QStringLiteral( "GPS" ), Qgis::Warning );
}
}

void QgsGpsMarker::setSize( int size )
Expand All @@ -53,7 +49,7 @@ void QgsGpsMarker::setCenter( const QgsPointXY &point )
}
catch ( QgsCsException &e ) //silently ignore transformation exceptions
{
QgsMessageLog::logMessage( QObject::tr( "Erorr transforming the map center point: %1" ).arg( e.what() ), QStringLiteral( "GPS" ), Qgis::Warning );
QgsMessageLog::logMessage( QObject::tr( "Error transforming the map center point: %1" ).arg( e.what() ), QStringLiteral( "GPS" ), Qgis::Warning );
return;
}
}
Expand Down
12 changes: 6 additions & 6 deletions tests/src/app/testqgsgpsinformationwidget.cpp
@@ -1,5 +1,5 @@
/***************************************************************************
testqgsgpsinformationwidget->cpp
testqgsgpsinformationwidget.cpp
--------------------------
Date : 2019-06-19
Copyright : (C) 2019 by Alessandro Pasotti
Expand Down Expand Up @@ -44,11 +44,11 @@ class TestQgsGpsInformationWidget : public QObject
private:
std::unique_ptr<QgsGpsInformationWidget> prepareWidget();
QDateTime _testWrite( QgsVectorLayer *vlayer, QgsGpsInformationWidget *widget, const QString &fieldName, Qt::TimeSpec timeSpec, bool commit = false );
QgsVectorLayer *tempLayer;
QgsVectorLayer *tempLayerString;
QgsVectorLayer *tempLayerDateTime;
QgsVectorLayer *tempLayerLineString;
QgsVectorLayer *tempGpkgLayerPointString;
QgsVectorLayer *tempLayer = nullptr;
QgsVectorLayer *tempLayerString = nullptr;
QgsVectorLayer *tempLayerDateTime = nullptr;
QgsVectorLayer *tempLayerLineString = nullptr;
QgsVectorLayer *tempGpkgLayerPointString = nullptr;
QgisApp *mQgisApp = nullptr;
};

Expand Down

0 comments on commit f220a7f

Please sign in to comment.