author | mickeyl <mickeyl> | 2004-01-03 18:27:07 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-01-03 18:27:07 (UTC) |
commit | 3889c8f853aa2d128f54389b17f08fc7b9150788 (patch) (side-by-side diff) | |
tree | 692bf0541e19d19f9ac93059463e4c4eb2e43e5f | |
parent | c69a2abd7718d8acddb4ce96a1909b33056e2dcd (diff) | |
download | opie-3889c8f853aa2d128f54389b17f08fc7b9150788.zip opie-3889c8f853aa2d128f54389b17f08fc7b9150788.tar.gz opie-3889c8f853aa2d128f54389b17f08fc7b9150788.tar.bz2 |
show GPS coordinates in the more common DMS format
-rw-r--r-- | noncore/net/wellenreiter/gui/gps.cpp | 66 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/gps.h | 13 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/mainwindow.cpp | 8 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/scanlist.cpp | 9 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/scanlist.h | 2 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/wellenreiter.cpp | 2 |
6 files changed, 82 insertions, 18 deletions
diff --git a/noncore/net/wellenreiter/gui/gps.cpp b/noncore/net/wellenreiter/gui/gps.cpp index 288afee..31f95ce 100644 --- a/noncore/net/wellenreiter/gui/gps.cpp +++ b/noncore/net/wellenreiter/gui/gps.cpp @@ -15,8 +15,12 @@ #include "gps.h" -#include <unistd.h> +/* QT */ #include <qtextstream.h> +/* STD */ +#include <stdlib.h> +#include <unistd.h> + GPS::GPS( QObject* parent, const char * name ) :QObject( parent, name ) @@ -65,5 +69,63 @@ GpsLocation GPS::position() const } } - return GpsLocation( -1.0, -1.0 ); + return GpsLocation( -111.111, -111.111 ); } + +QString GpsLocation::dmsPosition() const +{ + if ( _latitude == -111.111 || _longitude == -111.11 ) + return "N/A"; + if ( _latitude == 0.0 && _longitude == 0.0 ) + return "NULL"; + + /* compute latitude */ + + QString dms = "N"; + if ( _latitude >= 0 ) dms.append( "+" ); + + int trunc = int( _latitude ); + float rest = _latitude - trunc; + + float minf = rest * 60; + int minutes = int( minf ); + + rest = minf - minutes; + int seconds = int( rest * 60 ); + + dms.append( QString::number( trunc ) ); + dms.append( "° " ); + dms.append( QString::number( ::abs( minutes ) ) ); + dms.append( "' " ); + dms.append( QString::number( ::abs( seconds ) ) ); + dms.append( "'' " ); + + /* compute longitude */ + + dms.append( " | W" ); + if ( _longitude > 0 ) dms.append( "+" ); + + trunc = int( _longitude ); + rest = _longitude - trunc; + + minf = rest * 60; + minutes = int( minf ); + + rest = minf - minutes; + seconds = int( rest * 60 ); + + dms.append( QString::number( trunc ) ); + dms.append( "° " ); + dms.append( QString::number( ::abs( minutes ) ) ); + dms.append( "' " ); + dms.append( QString::number( ::abs( seconds ) ) ); + dms.append( "'' " ); + + return dms; +} + + + + + + diff --git a/noncore/net/wellenreiter/gui/gps.h b/noncore/net/wellenreiter/gui/gps.h index 8143fe4..cfe1cdb 100644 --- a/noncore/net/wellenreiter/gui/gps.h +++ b/noncore/net/wellenreiter/gui/gps.h @@ -20,10 +20,15 @@ #include <qsocket.h> -struct GpsLocation +class GpsLocation { - GpsLocation( const float& lat, const float& lon ) : latitude(lat), longitude(lon) {}; + public: + GpsLocation( const float& lat, const float& lon ) : _latitude(lat), _longitude(lon) {}; ~GpsLocation() {}; - float latitude; - float longitude; + float latitude() const { return _latitude; }; + float longitude() const { return _longitude; }; + QString dmsPosition() const; + private: + float _latitude; + float _longitude; }; diff --git a/noncore/net/wellenreiter/gui/mainwindow.cpp b/noncore/net/wellenreiter/gui/mainwindow.cpp index ca9851c..d4e3279 100644 --- a/noncore/net/wellenreiter/gui/mainwindow.cpp +++ b/noncore/net/wellenreiter/gui/mainwindow.cpp @@ -225,9 +225,9 @@ void WellenreiterMainWindow::demoAddStations() //mw = 0; // test SIGSGV handling - mw->netView()->addNewItem( "managed", "Vanille", OMacAddress::fromString("00:00:20:EF:A6:43"), true, 6, 80, GpsLocation( 10.10, 20.20 ) ); + mw->netView()->addNewItem( "managed", "Vanille", OMacAddress::fromString("00:00:20:EF:A6:43"), true, 6, 80, GpsLocation( 39.8794, -94.0936) ); mw->netView()->addNewItem( "managed", "Vanille", OMacAddress::fromString("00:30:6D:EF:A6:23"), true, 11, 10, GpsLocation( 0.0, 0.0 ) ); - mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:A0:F8:E7:16:22"), false, 3, 10, GpsLocation( 5.5, 2.3 ) ); - mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:AA:01:E7:56:62"), false, 3, 15, GpsLocation( 2.3, 5.5 ) ); - mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:B0:8E:E7:56:E2"), false, 3, 20, GpsLocation( -10.0, -20.5 ) ); + mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:03:F8:E7:16:22"), false, 3, 10, GpsLocation( 5.5, 2.3 ) ); + mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:04:01:E7:56:62"), false, 3, 15, GpsLocation( 2.3, 5.5 ) ); + mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:05:8E:E7:56:E2"), false, 3, 20, GpsLocation( -10.0, -20.5 ) ); } diff --git a/noncore/net/wellenreiter/gui/scanlist.cpp b/noncore/net/wellenreiter/gui/scanlist.cpp index 1cca507..d89c71f 100644 --- a/noncore/net/wellenreiter/gui/scanlist.cpp +++ b/noncore/net/wellenreiter/gui/scanlist.cpp @@ -190,5 +190,5 @@ void MScanListView::addNewItem( const QString& type, MScanListItem* station = new MScanListItem( network, type, "", macaddr, wep, channel, signal ); station->setManufacturer( mac.manufacturer() ); - station->setLocation( loc.latitude, loc.longitude ); + station->setLocation( loc.dmsPosition() ); if ( type == "managed" ) @@ -534,10 +534,7 @@ void MScanListItem::setManufacturer( const QString& manufacturer ) -void MScanListItem::setLocation( const float& latitude, const float& longitude ) +void MScanListItem::setLocation( const QString& location ) { - if ( latitude == 0.0 || longitude == 0.0 ) - setText( col_location, "N/A" ); - else - setText( col_location, QString().sprintf( "%.2f / %.2f", latitude, longitude ) ); + setText( col_location, location ); } diff --git a/noncore/net/wellenreiter/gui/scanlist.h b/noncore/net/wellenreiter/gui/scanlist.h index a9b74f1..6cd8fc0 100644 --- a/noncore/net/wellenreiter/gui/scanlist.h +++ b/noncore/net/wellenreiter/gui/scanlist.h @@ -104,5 +104,5 @@ class MScanListItem: public OListViewItem void setManufacturer( const QString& manufacturer ); - void setLocation( const float& latitude, const float& longitude ); + void setLocation( const QString& location ); virtual OListViewItem* childFactory(); diff --git a/noncore/net/wellenreiter/gui/wellenreiter.cpp b/noncore/net/wellenreiter/gui/wellenreiter.cpp index 9255a6d..5575d6e 100644 --- a/noncore/net/wellenreiter/gui/wellenreiter.cpp +++ b/noncore/net/wellenreiter/gui/wellenreiter.cpp @@ -190,5 +190,5 @@ void Wellenreiter::handleBeacon( OPacket* p, OWaveLanManagementPacket* beacon ) qDebug( "Wellenreiter::gathering GPS data..." ); loc = gps->position(); - qDebug( "Wellenreiter::GPS data received is ( %f , %f )", loc.latitude, loc.longitude ); + qDebug( "Wellenreiter::GPS data received is ( %f , %f ) - dms string = '%s'", loc.latitude(), loc.longitude(), loc.dmsPosition().latin1() ); } |