Created new class GpsLocation that handles communication with gps. It
authorNiko Böckerman <niko.bockerman@gmail.com>
Fri, 31 Dec 2010 11:01:20 +0000 (13:01 +0200)
committerniko <niko@nikosdesktop.(none)>
Fri, 31 Dec 2010 11:01:20 +0000 (13:01 +0200)
also inherits Location so that it can be used with the same interface.

Ui integration is not implemented yet.

zouba/src/gui/routelegwidget.cpp
zouba/src/gui/searchdisplay.cpp
zouba/src/logic/gpslocation.cpp [new file with mode: 0644]
zouba/src/logic/gpslocation.h [new file with mode: 0644]
zouba/src/logic/location.cpp
zouba/src/logic/location.h
zouba/src/logic/locations.cpp
zouba/src/logic/locations.h
zouba/zouba.pro

index 24ee522..52ac8df 100644 (file)
@@ -47,6 +47,8 @@ void RouteLegWidget::setDisplay(RouteLeg *leg)
     case TRAM:
         this->ui->image->setPixmap(QIcon(":/reittiopas/tram").pixmap(picSize));
         break;
+    case WALK:
+        break;
     }
     this->ui->image->adjustSize();
 }
index b4c6ff9..5a1e02c 100644 (file)
@@ -179,8 +179,7 @@ void SearchDisplay::on_searchButton_clicked()
         from = new Location(*from);
     } else {
         qDebug() << "Written text differs from the text in the combo box.";
-        from = new Location("Temp");
-        from->setAddress(this->ui->from_edit->text());
+        from = new Location("Temp", this->ui->from_edit->text());
     }
 
     if (dest != NULL && this->ui->dest_edit->text() == dest->address()) {
@@ -188,8 +187,7 @@ void SearchDisplay::on_searchButton_clicked()
         dest = new Location(*dest);
     } else {
         qDebug() << "Written text differs from the text in the combo box.";
-        dest = new Location("Temp");
-        dest->setAddress(this->ui->dest_edit->text());
+        dest = new Location("Temp", this->ui->dest_edit->text());
     }
 
     qDebug() << "Starting route search";
diff --git a/zouba/src/logic/gpslocation.cpp b/zouba/src/logic/gpslocation.cpp
new file mode 100644 (file)
index 0000000..5e8a08b
--- /dev/null
@@ -0,0 +1,235 @@
+#include "gpslocation.h"
+
+#include <QDebug>
+
+GpsLocation::GpsLocation(QObject *parent) :
+    QObject(parent), Location("0", "0", "GPS", "GPS"),
+    m_gps(QGeoPositionInfoSource::createDefaultSource(this)), m_active(false),
+    m_calculated(false),
+    latitude(0), longitude(0)
+{
+    m_valid = false;
+    m_gps->setUpdateInterval(20000);
+    connect(m_gps, SIGNAL(positionUpdated(QGeoPositionInfo)),
+            this, SLOT(updateLocation(QGeoPositionInfo)));
+    connect(m_gps, SIGNAL(updateTimeout()),
+            this, SLOT(timeout()));
+}
+
+GpsLocation::~GpsLocation()
+{
+    delete m_gps;
+}
+
+void GpsLocation::enableGps(bool enable)
+{
+    if (enable)
+        this->m_gps->startUpdates();
+    else
+        this->m_gps->stopUpdates();
+
+    emit(this->gpsLocationUpdatingChanged(enable));
+}
+
+void GpsLocation::updateLocation(QGeoPositionInfo positionInfo)
+{
+    this->latitude = positionInfo.coordinate().latitude();
+    this->longitude = positionInfo.coordinate().longitude();
+
+    this->m_calculated = false;
+    this->m_valid = true;
+
+    emit(this->gpsLocationChanged(this));
+}
+
+void GpsLocation::timeout()
+{
+    qDebug() << "GPS sent timeout while updating.";
+}
+
+void GpsLocation::calculateXY()
+{
+    KKJ outX(0);
+    KKJ outY(0);
+
+    WGS84lola_to_KKJxy(this->longitude, this->latitude, &outX, &outY);
+
+    this->m_x.setNum(outX);
+    this->m_y.setNum(outY);
+
+    this->m_calculated = true;
+}
+
+QString GpsLocation::x()
+{
+    if (!this->m_calculated)
+    {
+        this->calculateXY();
+    }
+    return this->m_x;
+}
+
+QString GpsLocation::y()
+{
+    if (!this->m_calculated)
+    {
+        this->calculateXY();
+    }
+    return this->m_y;
+}
+
+const double KkjZoneInfo[6][2] = {
+    {18.0,  500000.0},
+    {21.0, 1500000.0},
+    {24.0, 2500000.0},
+    {27.0, 3500000.0},
+    {30.0, 4500000.0},
+    {33.0, 5500000.0}
+};
+
+// Degrees to radians
+double radians(double deg)
+{
+    return deg * M_PI / 180.0;
+}
+
+// Radians to degrees
+double degrees(double rad)
+{
+    return rad * 180.0 / M_PI;
+}
+
+// Function:  KKJ_Zone_I
+int KKJ_Zone_I(KKJ easting)
+{
+    int zoneNumber = floor(easting / 1000000.0);
+    if (zoneNumber < 0 || zoneNumber > 5) {
+        zoneNumber = -1;
+    }
+
+    return zoneNumber;
+}
+
+// Function:  KKJ_Zone_Lo
+int KKJ_Zone_Lo(double kkjlo)
+{
+    // determine the zonenumber from KKJ easting
+    // takes KKJ zone which has center meridian
+    // longitude nearest (in math value) to
+    // the given KKJ longitude
+    int zoneNumber = 5;
+    while (zoneNumber >= 0) {
+        if (fabs(kkjlo - KkjZoneInfo[zoneNumber][0]) <= 1.5) {
+            break;
+        }
+        zoneNumber--;
+    }
+
+    return zoneNumber;
+}
+
+
+// Function:  KKJlalo_to_WGS84lalo
+void KKJlola_to_WGS84lola(double kkjlo, double kkjla, double *outLongitude, double *outLatitude)
+{
+    double dLa = radians(0.124867E+01 + -0.269982E+00 * kkjla + 0.191330E+00 * kkjlo + 0.356119E-02 * kkjla * kkjla + -0.122312E-02 * kkjla * kkjlo + -0.335514E-03 * kkjlo * kkjlo) / 3600.0;
+    double dLo = radians(-0.286111E+02 + 0.114183E+01 * kkjla + -0.581428E+00 * kkjlo + -0.152421E-01 * kkjla * kkjla + 0.118177E-01 * kkjla * kkjlo + 0.826646E-03 * kkjlo * kkjlo) / 3600.0;
+
+    *outLatitude = degrees(radians(kkjla) + dLa);
+    *outLongitude = degrees(radians(kkjlo) + dLo);
+}
+
+
+// Function:  WGS84lalo_to_KKJlalo
+void WGS84lola_to_KKJlola(double longitude, double latitude, double *outLongitude, double *outLatitude)
+{
+    double dLa = radians(-0.124766E+01 + 0.269941E+00 * latitude + -0.191342E+00 * longitude + -0.356086E-02 * latitude * latitude + 0.122353E-02 * latitude * longitude + 0.335456E-03 * longitude * longitude) / 3600.0;
+    double dLo = radians(0.286008E+02 + -0.114139E+01 * latitude + 0.581329E+00 * longitude + 0.152376E-01 * latitude * latitude + -0.118166E-01 * latitude * longitude + -0.826201E-03 * longitude * longitude) / 3600.0;
+
+    *outLatitude = degrees(radians(latitude) + dLa);
+    *outLongitude = degrees(radians(longitude) + dLo);
+}
+
+
+// Function:  KKJlalo_to_KKJxy
+void KKJlola_to_KKJxy(double lon, double lat, int zoneNumber, KKJ *outX, KKJ *outY)
+{
+    // Hayford ellipsoid
+    double a = 6378388.0;
+    double f  = 1.0 / 297.0;
+    double b  = (1.0 - f) * a;
+    double bb = b * b;
+    double c  = (a / b) * a;
+    double ee = (a * a - bb) / bb;
+    double n = (a - b) / (a + b);
+    double nn = n * n;
+
+    double Lo = radians(lon) - radians(KkjZoneInfo[zoneNumber][0]);
+    double cosLa = cos(radians(lat));
+    double NN = ee * cosLa * cosLa;
+    double LaF = atan(tan(radians(lat)) / cos(Lo * sqrt(1.0 + NN)));
+    double cosLaF = cos(LaF);
+    double t = (tan(Lo) * cosLaF) / sqrt(1.0 + ee * cosLaF * cosLaF);
+    double A = a / (1.0 + n);
+    double A1 = A * (1.0 + nn / 4.0 + nn * nn / 64.0);
+    double A2 = A * 1.5 * n * (1.0 - nn / 8.0);
+    double A3 = A * 0.9375 * nn * (1.0 - nn / 4.0);
+    double A4 = A * 35.0 / 48.0 * nn * n;
+
+    *outY = A1 * LaF - A2 * sin(2.0 * LaF) + A3 * sin(4.0 * LaF) - A4 * sin(6.0 * LaF);
+    *outX = c * log(t + sqrt(1.0 + t * t)) + 500000.0 + zoneNumber * 1000000.0;
+}
+
+// Function:  KKJxy_to_KKJlalo
+void KKJxy_to_KKJlola(KKJ x, KKJ y, double *outLongitude, double *outLatitude)
+{
+    // Scan iteratively the target area, until find matching
+    // KKJ coordinate value.  Area is defined with Hayford Ellipsoid.
+    int zoneNumber = KKJ_Zone_I(x);
+    double minLo = radians(18.5);
+    double maxLo = radians(32.0);
+    double minLa = radians(59.0);
+    double maxLa = radians(70.5);
+
+    int i = 1;
+    KKJ tmpX, tmpY;
+
+    while (i < 35) {
+        double deltaLo = maxLo - minLo;
+        double deltaLa = maxLa - minLa;
+        *outLongitude = degrees(minLo + 0.5 * deltaLo);
+        *outLatitude = degrees(minLa + 0.5 * deltaLa);
+        KKJlola_to_KKJxy(*outLongitude, *outLatitude, zoneNumber, &tmpX, &tmpY);
+        if (tmpY < y) {
+            minLa = minLa + 0.45 * deltaLa;
+        } else {
+            maxLa = minLa + 0.55 * deltaLa;
+        }
+
+        if (tmpX < x) {
+            minLo = minLo + 0.45 * deltaLo;
+        } else {
+            maxLo = minLo + 0.55 * deltaLo;
+        }
+
+        i++;
+    }
+}
+
+void WGS84lola_to_KKJxy(double longitude, double latitude, KKJ *outX, KKJ *outY)
+{
+    double kkjlo, kkjla;
+
+    WGS84lola_to_KKJlola(longitude, latitude, &kkjlo, &kkjla);
+    int zoneNumber = KKJ_Zone_Lo(kkjlo);
+    KKJlola_to_KKJxy(kkjlo, kkjla, zoneNumber, outX, outY);
+}
+
+void KKJxy_to_WGS84lola(KKJ x, KKJ y, double *outLongitude, double *outLatitude)
+{
+    double kkjlo, kkjla;
+
+    KKJxy_to_KKJlola(x, y, &kkjlo, &kkjla);
+    KKJlola_to_WGS84lola(kkjlo, kkjla, outLongitude, outLatitude);
+
+}
diff --git a/zouba/src/logic/gpslocation.h b/zouba/src/logic/gpslocation.h
new file mode 100644 (file)
index 0000000..580fb62
--- /dev/null
@@ -0,0 +1,92 @@
+#ifndef GPSLOCATION_H
+#define GPSLOCATION_H
+
+#include <QObject>
+#include <QGeoPositionInfo>
+#include <QGeoPositionInfoSource>
+#include <math.h>
+
+#include "location.h"
+
+typedef uint KKJ;
+
+QTM_USE_NAMESPACE;
+
+class GpsLocation : public QObject, public Location
+{
+    Q_OBJECT
+public:
+    explicit GpsLocation(QObject *parent = 0);
+    ~GpsLocation();
+
+    QString x();
+    QString y();
+
+signals:
+    void gpsLocationChanged(GpsLocation *newLocation);
+    void gpsLocationUpdatingChanged(bool isEnabled);
+
+public slots:
+    void enableGps(bool enable);
+
+private slots:
+    void updateLocation( QGeoPositionInfo positionInfo );
+    void timeout();
+
+private:
+    void calculateXY();
+
+    QGeoPositionInfoSource *m_gps;
+    bool m_active, m_calculated;
+    qreal latitude, longitude;
+
+};
+
+/**
+   * Transformes WGS84 longitude/latitude coordinates to KKJ x/y coordinates.
+   * @param longitude the input longitude in degrees
+   * @param latitude the input latitude in degrees
+   * @param outX the result x (easting)
+   * @param outY the result y (northing)
+   */
+void WGS84lola_to_KKJxy(double longitude, double latitude, KKJ *outX, KKJ *outY);
+
+/**
+   * Transformes KKJ x/y coordinates to WGS84 longitude/latitude coordinates.
+   * @param x the input x (easting)
+   * @param y the input y (northing)
+   * @param outLongitude the result longitude in degrees
+   * @param outLatitude the result latitude in degrees
+   */
+void KKJxy_to_WGS84lola(KKJ x, KKJ y, double *outLongitude, double *outLatitude);
+
+// Degrees to radians
+double radians(double deg);
+
+// Radians to degrees
+double degrees(double rad);
+
+// Constants
+// Longitude0 and Center meridian of KKJ bands
+//static const double KkjZoneInfo[][2];
+
+// Function:  KKJ_Zone_I
+int KKJ_Zone_I(KKJ easting);
+
+// Function:  KKJ_Zone_Lo
+int KKJ_Zone_Lo(double kkjlo);
+
+// Function:  KKJlalo_to_WGS84lalo
+void KKJlola_to_WGS84lola(double kkjlo, double kkjla, double *outLongitude, double *outLatitude);
+
+// Function:  WGS84lalo_to_KKJlalo
+void WGS84lola_to_KKJlola(double longitude, double latitude, double *outLongitude, double *outLatitude);
+
+// Function:  KKJlalo_to_KKJxy
+void KKJlola_to_KKJxy(double lon, double lat, int zoneNumber, KKJ *outX, KKJ *outY);
+
+// Function:  KKJxy_to_KKJlalo
+void KKJxy_to_KKJlola(KKJ x, KKJ y, double *outLongitude, double *outLatitude);
+
+
+#endif // GPSLOCATION_H
index e5193ec..0a392e2 100644 (file)
 
 #include <math.h>
 
-const double KkjZoneInfo[6][2] = {
-    {18.0,  500000.0},
-    {21.0, 1500000.0},
-    {24.0, 2500000.0},
-    {27.0, 3500000.0},
-    {30.0, 4500000.0},
-    {33.0, 5500000.0}
-};
-
-#ifdef Q_WS_MAEMO_5
-QTM_USE_NAMESPACE
-#endif
-
-        Location::Location( const QString &x, const QString &y, const QString &label ) :
+Location::Location( const QString &x, const QString &y, const QString &label, const QString &address ) :
         m_label(label),
-        m_address(QString()),
+        m_address(address),
         m_x(x),
         m_y(y),
         m_valid(true)
 {
 }
-#ifdef Q_WS_MAEMO_5
-Location::Location(const QGeoPositionInfo &positionInfo, const QString &label) :
+
+Location::Location(const QString &label, const QString &address) :
         m_label(label),
-        m_address(QString()),
-        m_x("0"),
-        m_y("0"),
+        m_address(address),
+        m_x(QString()),
+        m_y(QString()),
         m_valid(false)
 {
-    setLocation(positionInfo);
-}
-
-void Location::setLocation(const QGeoPositionInfo &positionInfo)
-{
-    qDebug() << "Setting new location based on GeoPositionInfo";
-    qreal latitude = positionInfo.coordinate().latitude();
-    qreal longitude = positionInfo.coordinate().longitude();
-
-    //qDebug() << "Calculating new values";
-
-    KKJ outX(0);
-    KKJ outY(0);
-
-    WGS84lola_to_KKJxy( longitude, latitude, &outX, &outY);
-
-    /*qDebug() << "Storing new values";
-    qDebug() << "x";
-    qDebug() << outX;
-    qDebug() << "y";
-    qDebug() << outY;*/
-
-    //qDebug() << "Setting x";
-    //this->m_x = QString("%1").arg(outX);
-    this->m_x.setNum(outX);
-    //qDebug() << "Setting y";
-    //this->m_y = QString("%1").arg(outY);
-    this->m_y.setNum(outY);
-    //qDebug() << "Setting as valid";
-    this->m_valid = true;
-    //emit(becomeValid());
-    //qDebug() << "Location set";
 }
-#endif
 
-void Location::setPosition(const QString &x, const QString &y)
+void Location::setPosition(const QString &x, const QString &y, const QString &address)
 {
     this->m_x = x;
     this->m_y = y;
+    this->m_address = address;
     this->m_valid = true;
 }
 
-Location::Location(const QString &label) :
-        m_label(label),
-        m_address(QString()),
-        m_x("0"),
-        m_y("0"),
-        m_valid(false)
-{
-}
-
-Location::Location(const Location &other) :
-    m_label(other.m_label),
-    m_address(other.m_address),
-    m_x(other.m_x),
-    m_y(other.m_y),
-    m_valid(other.m_valid)
-{
-}
-
-/*Location* Location::copy_Location(const Location *other)
-{
-    Location *ret = new Location(other->m_x, other->m_y, other->m_label);
-    ret->m_address = other->m_address;
-    ret->m_valid = other->m_valid;
-    return ret;
-}*/
-
-
 QString Location::x() const
 {
     return m_x;
@@ -134,11 +62,6 @@ QString Location::label() const
     return m_label;
 }
 
-void Location::setAddress(const QString &address)
-{
-    m_address = address;
-}
-
 QString Location::address() const
 {
     return m_address;
@@ -148,150 +71,3 @@ bool Location::isValid() const
 {
     return m_valid;
 }
-
-// Degrees to radians
-double radians(double deg)
-{
-    return deg * M_PI / 180.0;
-}
-
-// Radians to degrees
-double degrees(double rad)
-{
-    return rad * 180.0 / M_PI;
-}
-
-// Function:  KKJ_Zone_I
-int KKJ_Zone_I(KKJ easting)
-{
-    int zoneNumber = floor(easting / 1000000.0);
-    if (zoneNumber < 0 || zoneNumber > 5) {
-        zoneNumber = -1;
-    }
-
-    return zoneNumber;
-}
-
-// Function:  KKJ_Zone_Lo
-int KKJ_Zone_Lo(double kkjlo)
-{
-    // determine the zonenumber from KKJ easting
-    // takes KKJ zone which has center meridian
-    // longitude nearest (in math value) to
-    // the given KKJ longitude
-    int zoneNumber = 5;
-    while (zoneNumber >= 0) {
-        if (fabs(kkjlo - KkjZoneInfo[zoneNumber][0]) <= 1.5) {
-            break;
-        }
-        zoneNumber--;
-    }
-
-    return zoneNumber;
-}
-
-
-// Function:  KKJlalo_to_WGS84lalo
-void KKJlola_to_WGS84lola(double kkjlo, double kkjla, double *outLongitude, double *outLatitude)
-{
-    double dLa = radians(0.124867E+01 + -0.269982E+00 * kkjla + 0.191330E+00 * kkjlo + 0.356119E-02 * kkjla * kkjla + -0.122312E-02 * kkjla * kkjlo + -0.335514E-03 * kkjlo * kkjlo) / 3600.0;
-    double dLo = radians(-0.286111E+02 + 0.114183E+01 * kkjla + -0.581428E+00 * kkjlo + -0.152421E-01 * kkjla * kkjla + 0.118177E-01 * kkjla * kkjlo + 0.826646E-03 * kkjlo * kkjlo) / 3600.0;
-
-    *outLatitude = degrees(radians(kkjla) + dLa);
-    *outLongitude = degrees(radians(kkjlo) + dLo);
-}
-
-
-// Function:  WGS84lalo_to_KKJlalo
-void WGS84lola_to_KKJlola(double longitude, double latitude, double *outLongitude, double *outLatitude)
-{
-    double dLa = radians(-0.124766E+01 + 0.269941E+00 * latitude + -0.191342E+00 * longitude + -0.356086E-02 * latitude * latitude + 0.122353E-02 * latitude * longitude + 0.335456E-03 * longitude * longitude) / 3600.0;
-    double dLo = radians(0.286008E+02 + -0.114139E+01 * latitude + 0.581329E+00 * longitude + 0.152376E-01 * latitude * latitude + -0.118166E-01 * latitude * longitude + -0.826201E-03 * longitude * longitude) / 3600.0;
-
-    *outLatitude = degrees(radians(latitude) + dLa);
-    *outLongitude = degrees(radians(longitude) + dLo);
-}
-
-
-// Function:  KKJlalo_to_KKJxy
-void KKJlola_to_KKJxy(double lon, double lat, int zoneNumber, KKJ *outX, KKJ *outY)
-{
-    // Hayford ellipsoid
-    double a = 6378388.0;
-    double f  = 1.0 / 297.0;
-    double b  = (1.0 - f) * a;
-    double bb = b * b;
-    double c  = (a / b) * a;
-    double ee = (a * a - bb) / bb;
-    double n = (a - b) / (a + b);
-    double nn = n * n;
-
-    double Lo = radians(lon) - radians(KkjZoneInfo[zoneNumber][0]);
-    double cosLa = cos(radians(lat));
-    double NN = ee * cosLa * cosLa;
-    double LaF = atan(tan(radians(lat)) / cos(Lo * sqrt(1.0 + NN)));
-    double cosLaF = cos(LaF);
-    double t = (tan(Lo) * cosLaF) / sqrt(1.0 + ee * cosLaF * cosLaF);
-    double A = a / (1.0 + n);
-    double A1 = A * (1.0 + nn / 4.0 + nn * nn / 64.0);
-    double A2 = A * 1.5 * n * (1.0 - nn / 8.0);
-    double A3 = A * 0.9375 * nn * (1.0 - nn / 4.0);
-    double A4 = A * 35.0 / 48.0 * nn * n;
-
-    *outY = A1 * LaF - A2 * sin(2.0 * LaF) + A3 * sin(4.0 * LaF) - A4 * sin(6.0 * LaF);
-    *outX = c * log(t + sqrt(1.0 + t * t)) + 500000.0 + zoneNumber * 1000000.0;
-}
-
-// Function:  KKJxy_to_KKJlalo
-void KKJxy_to_KKJlola(KKJ x, KKJ y, double *outLongitude, double *outLatitude)
-{
-    // Scan iteratively the target area, until find matching
-    // KKJ coordinate value.  Area is defined with Hayford Ellipsoid.
-    int zoneNumber = KKJ_Zone_I(x);
-    double minLo = radians(18.5);
-    double maxLo = radians(32.0);
-    double minLa = radians(59.0);
-    double maxLa = radians(70.5);
-
-    int i = 1;
-    KKJ tmpX, tmpY;
-
-    while (i < 35) {
-        double deltaLo = maxLo - minLo;
-        double deltaLa = maxLa - minLa;
-        *outLongitude = degrees(minLo + 0.5 * deltaLo);
-        *outLatitude = degrees(minLa + 0.5 * deltaLa);
-        KKJlola_to_KKJxy(*outLongitude, *outLatitude, zoneNumber, &tmpX, &tmpY);
-        if (tmpY < y) {
-            minLa = minLa + 0.45 * deltaLa;
-        } else {
-            maxLa = minLa + 0.55 * deltaLa;
-        }
-
-        if (tmpX < x) {
-            minLo = minLo + 0.45 * deltaLo;
-        } else {
-            maxLo = minLo + 0.55 * deltaLo;
-        }
-
-        i++;
-    }
-}
-
-void WGS84lola_to_KKJxy(double longitude, double latitude, KKJ *outX, KKJ *outY)
-{
-    double kkjlo, kkjla;
-
-    WGS84lola_to_KKJlola(longitude, latitude, &kkjlo, &kkjla);
-    int zoneNumber = KKJ_Zone_Lo(kkjlo);
-    KKJlola_to_KKJxy(kkjlo, kkjla, zoneNumber, outX, outY);
-}
-
-void KKJxy_to_WGS84lola(KKJ x, KKJ y, double *outLongitude, double *outLatitude)
-{
-    double kkjlo, kkjla;
-
-    KKJxy_to_KKJlola(x, y, &kkjlo, &kkjla);
-    KKJlola_to_WGS84lola(kkjlo, kkjla, outLongitude, outLatitude);
-
-}
index 390ebe7..a354e9d 100644 (file)
@@ -2,34 +2,27 @@
 #define LOCATION_H
 
 #include <QString>
-#include <QObject>
-#include <QNetworkAccessManager>
-#include <QNetworkReply>
-#include <QGeoPositionInfo>
-#include <math.h>
 
-QTM_USE_NAMESPACE;
 
 class Location
 {
 
 public:
-    Location( const QString &x, const QString &y, const QString &label=QString() );
-    Location( const QGeoPositionInfo &positionInfo, const QString &label=QString() );
-    Location( const QString &label=QString() );
-    Location(const Location &location);
+    Location( const QString &x, const QString &y, const QString &label, const QString &address = QString());
+
+    //Location( const QGeoPositionInfo &positionInfo, const QString &label=QString() );
+    Location( const QString &label, const QString &address);
+    //Location(const Location &location);
     //Location(const Location *location);
 
+    Location& operator=(const Location &other);
 
     QString x() const;
-
     QString y() const;
 
-    void setLocation( const QGeoPositionInfo &positionInfo );
+    void setPosition(const QString &x, const QString &y, const QString &address = QString());
 
-    void setPosition(const QString &x, const QString &y);
-
-    void setAddress( const QString &address );
+    //void setAddress( const QString &address );
     QString address() const;
 
     void setLabel( const QString &label );
@@ -37,12 +30,7 @@ public:
 
     bool isValid() const;
 
-/*Q_SIGNALS:
-    void becomeValid();
-    void becomeInValid();
-    void busy( bool busy );*/
-
-private:
+protected:
     QString m_label;
     QString m_address;
     QString m_x;
@@ -51,53 +39,6 @@ private:
 };
 
 
-typedef uint KKJ;
-
-/**
-   * Transformes WGS84 longitude/latitude coordinates to KKJ x/y coordinates.
-   * @param longitude the input longitude in degrees
-   * @param latitude the input latitude in degrees
-   * @param outX the result x (easting)
-   * @param outY the result y (northing)
-   */
-void WGS84lola_to_KKJxy(double longitude, double latitude, KKJ *outX, KKJ *outY);
-
-/**
-   * Transformes KKJ x/y coordinates to WGS84 longitude/latitude coordinates.
-   * @param x the input x (easting)
-   * @param y the input y (northing)
-   * @param outLongitude the result longitude in degrees
-   * @param outLatitude the result latitude in degrees
-   */
-void KKJxy_to_WGS84lola(KKJ x, KKJ y, double *outLongitude, double *outLatitude);
-
-// Degrees to radians
-double radians(double deg);
-
-// Radians to degrees
-double degrees(double rad);
-
-// Constants
-// Longitude0 and Center meridian of KKJ bands
-//static const double KkjZoneInfo[][2];
-
-// Function:  KKJ_Zone_I
-int KKJ_Zone_I(KKJ easting);
-
-// Function:  KKJ_Zone_Lo
-int KKJ_Zone_Lo(double kkjlo);
-
-// Function:  KKJlalo_to_WGS84lalo
-void KKJlola_to_WGS84lola(double kkjlo, double kkjla, double *outLongitude, double *outLatitude);
-
-// Function:  WGS84lalo_to_KKJlalo
-void WGS84lola_to_KKJlola(double longitude, double latitude, double *outLongitude, double *outLatitude);
-
-// Function:  KKJlalo_to_KKJxy
-void KKJlola_to_KKJxy(double lon, double lat, int zoneNumber, KKJ *outX, KKJ *outY);
-
-// Function:  KKJxy_to_KKJlalo
-void KKJxy_to_KKJlola(KKJ x, KKJ y, double *outLongitude, double *outLatitude);
 
 
 #endif // LOCATION_H
index 3504cbb..62f70b6 100644 (file)
@@ -29,7 +29,7 @@ Locations* Locations::GetInstance()
 Locations::Locations() :
         m_locationStorage(QHash<QString,Location *>()),
         m_indexStorage(QList<QString>()),
-        m_gpsLocation(new Location("GPS"))
+        m_gpsLocation(new GpsLocation())
 {
     this->restoreLocations();
     qDebug() << "Size of index storage:" << this->m_indexStorage.size();
@@ -103,16 +103,14 @@ void Locations::restoreLocations()
         qDebug() << "Restoring " << label;
         Location *location;
         if (valid) {
-            location = new Location( x, y, label );
-            location->setAddress(address);
+            location = new Location( x, y, label, address );
+            this->m_locationStorage[label] = location;
+            this->m_indexStorage.append(label);
+            if (index != 0)
+                tempIndex.insert(label, index);
         }
-        else
-            location = new Location(label);
 
-        this->m_locationStorage[label] = location;
-        this->m_indexStorage.append(label);
-        if (index != 0)
-            tempIndex.insert(label, index);
+
     }
 
     settings.endGroup();
@@ -300,7 +298,7 @@ Location *Locations::getLocation(const int &index) const
     return this->m_locationStorage;
 }*/
 
-Location *Locations::getGpsLocation() const
+GpsLocation *Locations::getGpsLocation() const
 {
     qDebug() << "GPS location requested.";
     return this->m_gpsLocation;
index 0ed119c..909c7a2 100644 (file)
@@ -2,6 +2,7 @@
 #define LOCATIONS_H
 
 #include "location.h"
+#include "gpslocation.h"
 
 #include <QHash>
 #include <QList>
@@ -24,7 +25,7 @@ public:
 
     Location *getLocation(const QString &label) const;
     Location *getLocation(const int&) const;
-    Location *getGpsLocation() const;
+    GpsLocation *getGpsLocation() const;
     int size() const;
 
     //const QHash<QString, Location *>& getLocations() const;
@@ -45,7 +46,7 @@ private:
 
     QHash<QString, Location*> m_locationStorage;
     QList<QString> m_indexStorage;
-    Location* m_gpsLocation;
+    GpsLocation* m_gpsLocation;
 
     static Locations *m_instance;
 };
index f7fb9d0..f49ecf7 100644 (file)
@@ -1,12 +1,6 @@
 TARGET      = zouba
 SOURCES += \
     src/main.cpp \
-    src/route.cpp \
-    src/route_p.cpp \
-    src/uicontroller.cpp \
-    src/ui.cpp \
-    src/locationbutton.cpp \
-    src/addressdialog.cpp \
     src/logic/ytv.cpp \
     src/logic/routepointgenerator.cpp \
     src/logic/routepoint.cpp \
@@ -21,15 +15,10 @@ SOURCES += \
     src/gui/routeresultwidget.cpp \
     src/gui/searchdisplay.cpp \
     src/gui/routeoneitemwidget.cpp \
-    src/gui/locationsdisplaywindow.cpp
+    src/gui/locationsdisplaywindow.cpp \
+    src/logic/gpslocation.cpp
 
 HEADERS += \
-    src/route.h \
-    src/route_p.h \
-    src/uicontroller.h \
-    src/ui.h \
-    src/locationbutton.h \
-    src/addressdialog.h \
     src/logic/ytv.h \
     src/logic/routepointgenerator.h \
     src/logic/routepoint.h \
@@ -44,7 +33,8 @@ HEADERS += \
     src/gui/routeresultwidget.h \
     src/gui/searchdisplay.h \
     src/gui/routeoneitemwidget.h \
-    src/gui/locationsdisplaywindow.h
+    src/gui/locationsdisplaywindow.h \
+    src/logic/gpslocation.h
 
 FORMS       += \
     src/gui/locationsdisplaywindow.ui \
@@ -79,10 +69,8 @@ QT=core gui network
 
 linux-g++-maemo5 {
 SOURCES += \
-    gpscontroller.cpp \
     src/gui/favoriteselectiondialog.cpp
 HEADERS += \
-    gpscontroller.h \
     src/gui/favoriteselectiondialog.h
 FORMS += \
     src/gui/favoriteselectiondialog.ui