void
QTMLocationProvider::positionUpdated(const QGeoPositionInfo &geoPosition)
{
    if (!geoPosition.isValid()) {
        NS_WARNING("Invalida geoposition received");
        return;
    }

    QGeoCoordinate coord = geoPosition.coordinate();
    double latitude = coord.latitude();
    double longitude = coord.longitude();
    double altitude = coord.altitude();
    double accuracy = geoPosition.attribute(QGeoPositionInfo::HorizontalAccuracy);
    double altitudeAccuracy = geoPosition.attribute(QGeoPositionInfo::VerticalAccuracy);
    double heading = geoPosition.attribute(QGeoPositionInfo::Direction);

    bool providesSpeed = geoPosition.hasAttribute(QGeoPositionInfo::GroundSpeed);
    double speed = geoPosition.attribute(QGeoPositionInfo::GroundSpeed);

    nsRefPtr<nsGeoPosition> p =
        new nsGeoPosition(latitude, longitude,
                          altitude, accuracy,
                          altitudeAccuracy, heading,
                          speed, geoPosition.timestamp().toTime_t());
    if (mCallback) {
        mCallback->Update(p);
    }
}
예제 #2
0
void GeolocationClientQt::positionUpdated(const QGeoPositionInfo &geoPosition)
{
    if (!geoPosition.isValid())
        return;

    QGeoCoordinate coord = geoPosition.coordinate();
    double latitude = coord.latitude();
    double longitude = coord.longitude();
    bool providesAltitude = (geoPosition.coordinate().type() == QGeoCoordinate::Coordinate3D);
    double altitude = coord.altitude();

    double accuracy = geoPosition.attribute(QGeoPositionInfo::HorizontalAccuracy);

    bool providesAltitudeAccuracy = geoPosition.hasAttribute(QGeoPositionInfo::VerticalAccuracy);
    double altitudeAccuracy = geoPosition.attribute(QGeoPositionInfo::VerticalAccuracy);

    bool providesHeading =  geoPosition.hasAttribute(QGeoPositionInfo::Direction);
    double heading = geoPosition.attribute(QGeoPositionInfo::Direction);

    bool providesSpeed = geoPosition.hasAttribute(QGeoPositionInfo::GroundSpeed);
    double speed = geoPosition.attribute(QGeoPositionInfo::GroundSpeed);

    double timeStampInSeconds = geoPosition.timestamp().toMSecsSinceEpoch() / 1000;

    m_lastPosition = GeolocationPosition::create(timeStampInSeconds, latitude, longitude,
                                                 accuracy, providesAltitude, altitude,
                                                 providesAltitudeAccuracy, altitudeAccuracy,
                                                 providesHeading, heading, providesSpeed, speed);

    WebCore::Page* page = QWebPagePrivate::core(m_page);
    page->geolocationController()->positionChanged(m_lastPosition.get());
}
예제 #3
0
void GPSTracker::positionUpdated(QGeoPositionInfo position) {
    if(tracking){
        addPosition(position);
    }
    emit positionUpdated(Point(position));
    horizontalAccuracy = position.attribute(QGeoPositionInfo::HorizontalAccuracy);
    verticalAccuracy   = position.attribute(QGeoPositionInfo::VerticalAccuracy);
    changeGPSStatus(RECEIVE);
}
예제 #4
0
void QgsQuickPositionKit::onPositionUpdated( const QGeoPositionInfo &info )
{
  bool hasPosition = info.coordinate().isValid();
  if ( hasPosition != mHasPosition )
  {
    mHasPosition = hasPosition;
    emit hasPositionChanged();
  }

  // Calculate position
  QgsPoint position = QgsPoint(
                        info.coordinate().longitude(),
                        info.coordinate().latitude(),
                        info.coordinate().altitude() ); // can be NaN

  if ( position != mPosition )
  {
    mPosition = position;
    emit positionChanged();
  }
  // calculate accuracy
  double accuracy;
  if ( info.hasAttribute( QGeoPositionInfo::HorizontalAccuracy ) )
    accuracy = info.attribute( QGeoPositionInfo::HorizontalAccuracy );
  else
    accuracy = -1;
  if ( !qgsDoubleNear( accuracy, mAccuracy ) )
  {
    mAccuracy = accuracy;
    emit accuracyChanged();
  }

  // calculate direction
  double direction;
  if ( info.hasAttribute( QGeoPositionInfo::Direction ) )
    direction = info.attribute( QGeoPositionInfo::Direction );
  else
    direction = -1;
  if ( !qgsDoubleNear( direction, mDirection ) )
  {
    mDirection = direction;
    emit directionChanged();
  }

  // recalculate projected/screen variables
  onMapSettingsUpdated();
}
예제 #5
0
void KTracks::on_acSelect_triggered()
{
   QModelIndexList selection = ui->tvTracks->selectionModel()->selectedRows();
   QAbstractItemModel *model = ui->tvTracks->model();

   if (!selection.isEmpty()) {
       QList<QGeoPositionInfo> trackList;
       trackList.clear();
       trackList = sql.selTrack(model->data(model->index(selection.at(0).row(),0)).toInt());

       ui->cpPlot->clearGraphs();
       ui->cpPlot->addGraph();

       QGeoPositionInfo tp;
       QVector<double> x;
       QVector<double> y;
       int cnt = trackList.count();
       x.resize(cnt);
       y.resize(cnt);

       //options
       int pType;
       if (ui->miAltitude->isChecked()) {
           ui->cpPlot->yAxis->setLabel("Altitude [m]");
           pType = 1; }
       if (ui->miDistance->isChecked()) {
           ui->cpPlot->yAxis->setLabel("Distance [m]");
           pType = 2; }
       if (ui->miSpeed->isChecked()) {
           ui->cpPlot->yAxis->setLabel("Speed [m/s]");
           pType = 3; }
       ui->cpPlot->xAxis->setLabel("time [hh:mm:ss]");

       for (int i=0; i<cnt; i++) {
           tp = trackList.value(i);
           x[i] = tp.timestamp().toTime_t();
           switch (pType) {
             case 1: {
               y[i] = tp.coordinate().altitude();
               break; }
             case 2: {
               y[i] = tp.coordinate().distanceTo(trackList.value(0).coordinate());
               break; }
             case 3: {
               y[i] = tp.attribute(QGeoPositionInfo::GroundSpeed);
               break; }
           } //switch
       } //for to

       ui->cpPlot->graph(0)->setData(x,y);
       // set axes ranges, so we see all data:
       ui->cpPlot->xAxis->setRange(x[0],x[cnt-1]);
       qSort(y.begin(), y.end());
       ui->cpPlot->yAxis->setRange(y.first(),y.last());
       //repaint
       ui->cpPlot->replot();

   } //selection.isempty
}
예제 #6
0
void TrackRecorder::positionUpdated(const QGeoPositionInfo &newPos) {
    if(newPos.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)) {
        m_accuracy = newPos.attribute(QGeoPositionInfo::HorizontalAccuracy);
    } else {
        m_accuracy = -1;
    }
    emit accuracyChanged();

    m_currentPosition = newPos.coordinate();
    emit currentPositionChanged();

    if(newPos.hasAttribute(QGeoPositionInfo::HorizontalAccuracy) &&
            (newPos.attribute(QGeoPositionInfo::HorizontalAccuracy) > 30.0)) {
        return;
    }

    if(m_tracking) {
        m_points.append(newPos);
        emit pointsChanged();
        emit timeChanged();
        if(m_isEmpty) {
            m_isEmpty = false;
            m_minLat = m_maxLat = newPos.coordinate().latitude();
            m_minLon = m_maxLon = newPos.coordinate().longitude();
            emit isEmptyChanged();
        }

        if(m_points.size() > 1) {
            // Next line triggers following compiler warning?
            // \usr\include\qt5\QtCore\qlist.h:452: warning: assuming signed overflow does not occur when assuming that (X - c) > X is always false [-Wstrict-overflow]
            m_distance += m_points.at(m_points.size()-2).coordinate().distanceTo(m_points.at(m_points.size()-1).coordinate());
            emit distanceChanged();
            if(newPos.coordinate().latitude() < m_minLat) {
                m_minLat = newPos.coordinate().latitude();
            } else if(newPos.coordinate().latitude() > m_maxLat) {
                m_maxLat = newPos.coordinate().latitude();
            }
            if(newPos.coordinate().longitude() < m_minLon) {
                m_minLon = newPos.coordinate().longitude();
            } else if(newPos.coordinate().longitude() > m_maxLon) {
                m_maxLon = newPos.coordinate().longitude();
            }
        }
        emit newTrackPoint(newPos.coordinate());
    }
}
void tst_QNmeaPositionInfoSource::startUpdates_waitForValidDateTime()
{
    // Tests that the class does not emit an update until it receives a
    // sentences with a valid date *and* time. All sentences before this
    // should be ignored, and any sentences received after this that do
    // not have a date should use the known date.

    QFETCH(QByteArray, bytes);
    QFETCH(QList<QDateTime>, dateTimes);
    QFETCH(QList<bool>, expectHorizontalAccuracy);
    QFETCH(QList<bool>, expectVerticalAccuracy);

    QNmeaPositionInfoSource source(m_mode);
    source.setUserEquivalentRangeError(5.1);
    QNmeaPositionInfoSourceProxyFactory factory;
    QNmeaPositionInfoSourceProxy *proxy = static_cast<QNmeaPositionInfoSourceProxy*>(factory.createProxy(&source));

    QSignalSpy spy(proxy->source(), SIGNAL(positionUpdated(QGeoPositionInfo)));
    proxy->source()->startUpdates();

    proxy->feedBytes(bytes);
    QTRY_COMPARE(spy.count(), dateTimes.count());

    for (int i=0; i<spy.count(); i++) {
        QGeoPositionInfo pInfo = spy[i][0].value<QGeoPositionInfo>();

        QCOMPARE(pInfo.timestamp(), dateTimes[i]);

        // Generated GGA/GSA sentences have hard coded HDOP of 3.5, which corrisponds to a
        // horizontal accuracy of 35.7, for the user equivalent range error of 5.1 set above.
        QCOMPARE(pInfo.hasAttribute(QGeoPositionInfo::HorizontalAccuracy),
                 expectHorizontalAccuracy[i]);
        if (pInfo.hasAttribute(QGeoPositionInfo::HorizontalAccuracy))
            QVERIFY(qFuzzyCompare(pInfo.attribute(QGeoPositionInfo::HorizontalAccuracy), 35.7));

        // Generate GSA sentences have hard coded VDOP of 4.0, which corrisponds to a vertical
        // accuracy of 40.8, for the user equivalent range error of 5.1 set above.
        QCOMPARE(pInfo.hasAttribute(QGeoPositionInfo::VerticalAccuracy),
                 expectVerticalAccuracy[i]);
        if (pInfo.hasAttribute(QGeoPositionInfo::VerticalAccuracy))
            QVERIFY(qFuzzyCompare(pInfo.attribute(QGeoPositionInfo::VerticalAccuracy), 40.8));
    }
}
void QGeoPositionInfoSourceAndroid::requestTimeout()
{
    AndroidPositioning::stopUpdates(androidClassKeyForSingleRequest);
    //no queued update to process -> timeout
    const int count = queuedSingleUpdates.count();

    if (!count) {
        emit updateTimeout();
        return;
    }

    //pick best
    QGeoPositionInfo best = queuedSingleUpdates[0];
    for (int i = 1; i < count; i++) {
        const QGeoPositionInfo info = queuedSingleUpdates[i];

        //anything newer by 20s is always better
        const int timeDelta = best.timestamp().secsTo(info.timestamp());
        if (abs(timeDelta) > 20) {
            if (timeDelta > 0)
                best = info;
            continue;
        }

        //compare accuracy
        if (info.hasAttribute(QGeoPositionInfo::HorizontalAccuracy) &&
                info.hasAttribute(QGeoPositionInfo::HorizontalAccuracy))
        {
            best = info.attribute(QGeoPositionInfo::HorizontalAccuracy) <
                    best.attribute(QGeoPositionInfo::HorizontalAccuracy) ? info : best;
            continue;
        }

        //prefer info with accuracy information
        if (info.hasAttribute(QGeoPositionInfo::HorizontalAccuracy))
            best = info;
    }

    queuedSingleUpdates.clear();
    emit positionUpdated(best);
}
예제 #9
0
// Testcase to check that values are passed correctly
void TestQGeoPositionInfoSource::updateValues()
{
    CHECK_SOURCE_VALID;

    QSignalSpy spy(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&)));
    m_source->startUpdates();
    QTRY_VERIFY_WITH_TIMEOUT(!spy.isEmpty(), 2000);
    QList<QVariant> list = spy.takeFirst();
    QGeoPositionInfo info;
    info = list.at(0).value<QGeoPositionInfo>();
    QCOMPARE(qFuzzyCompare(info.coordinate().latitude(), 21), TRUE );
    QCOMPARE(qFuzzyCompare(info.coordinate().longitude(), 31), TRUE );
    QCOMPARE(qFuzzyCompare(info.coordinate().altitude(), 5.1), TRUE );
    QCOMPARE(qFuzzyCompare(info.attribute(QGeoPositionInfo::HorizontalAccuracy), 8), TRUE );
    QCOMPARE(qFuzzyCompare(info.attribute(QGeoPositionInfo::VerticalAccuracy), 9), TRUE );
    QDateTime dateTime;
    dateTime.setTime_t(99998);
    // there is some rounding difference impacting at sec level
    // hence don't compare directly
    QCOMPARE(info.timestamp().date(),dateTime.date());
    QCOMPARE(info.timestamp().time().hour(),dateTime.time().hour());
}
예제 #10
0
void LocationData::onPositionChanged(const QGeoPositionInfo& info)
{
    emit positionChanged(info);
    if (info.isValid())
    {
        const QGeoCoordinate& c = info.coordinate();
        if (c.isValid())
        {
            double lat = c.latitude();
            double lon = c.longitude();
            double alt = c.altitude();
            //qDebug() << "LocationData::onPositionChanged()" << lat << lon << alt;
            if ((latitude != lat) || (longitude != lon))
            {
                latitude  = lat;
                mask |= LATMASK;
                longitude = lon;
                mask |= LONMASK;
            }
            if (altitude != alt)
            {
                altitude = alt;
                mask |= ALTMASK;
            }
            emit positionChanged(lat,lon,alt);
        }
        if (info.hasAttribute(QGeoPositionInfo::GroundSpeed))
        {
            double s = info.attribute(QGeoPositionInfo::GroundSpeed);
            emit speedChanged(s);
        }
        if (info.hasAttribute(QGeoPositionInfo::Direction))
        {
            double c = info.attribute(QGeoPositionInfo::Direction);
            emit courseChanged(c);
        }
    }
}
예제 #11
0
int CLbsPositionLogger::Write(const QGeoPositionInfo &info)
{
    int nRet = 0;

    QString szContext;
    szContext = QString::number(info.timestamp().toUTC().toTime_t()) + ","
            + QString::number(info.coordinate().latitude()) + ","
            + QString::number(info.coordinate().longitude()) + ",";
    if(!qIsNaN(info.coordinate().altitude()))
        szContext += QString::number(info.coordinate().altitude());
    szContext += ",";
    if(info.hasAttribute(QGeoPositionInfo::HorizontalAccuracy))
        szContext += QString::number(info.attribute(QGeoPositionInfo::HorizontalAccuracy));
    szContext += ",";
    if(info.hasAttribute(QGeoPositionInfo::Direction))
        szContext += QString::number(info.attribute(QGeoPositionInfo::Direction));
    szContext += ",";
    if(info.hasAttribute(QGeoPositionInfo::GroundSpeed))
        szContext += QString::number(info.attribute(QGeoPositionInfo::GroundSpeed));
    szContext += "\n";
    m_logFile.write(szContext.toStdString().c_str(), szContext.length());
    return nRet;
}
예제 #12
0
void QGeoPositionInfoSourceMaemo::newPositionUpdate(const QGeoPositionInfo &position)
{    
    /*
        Invalid fixes have NaN for horizontal accuracy regardless of
        whether they come from satellite or non-satellite position methods.

        Satellite fixes always have LOCATION_GPS_DEVICE_TIME_SET.
        If this is not set and we have a numeric value for horizontal
        accuracy then we are dealing with a non-satellite based positioning
        method.

        Since QGeoPositionInfo instances are only considered valid if
        they have a valid coordinate and a valid timestamp, we use
        the current date and time as the timestamp for the network based
        positioning.  This will help in the case where someone wants to
        reply a journey from a log file.

        Based on some logging it looks like satellite and non-satellite
        methods can be distinguished (after the initial fix) by whether
        the time has been set and / or whether the horizontal accuracy
        is above or below around 500 metres.  Using the timestamp
        appears to be more definitive than using the accuracy.
    */

    const bool horizontalAccuracyDefined = !qIsNaN(position.attribute(QGeoPositionInfo::HorizontalAccuracy));
    const bool hasTimeStamp = !position.timestamp().isNull();

    if (horizontalAccuracyDefined) {
        if (hasTimeStamp) {
            //Valid satellite fix
            lastUpdateFromSatellite = position;
        } else {
            //Valid non-satellite fix
            QGeoPositionInfo networkPosition(position);
            networkPosition.setTimestamp(QDateTime::currentDateTime());
            lastUpdateFromNetwork = networkPosition;
        }
    } else {
        //Invalid position update
        if (hasTimeStamp) {
            lastUpdateFromSatellite = QGeoPositionInfo();
        } else {
            lastUpdateFromNetwork = QGeoPositionInfo();
        }
    }
}
예제 #13
0
void Daemon::positionUpdated(QGeoPositionInfo gpsPos)
{
    qreal haMeters = 0;

    if(gpsPos.isValid()) {
        haMeters = gpsPos.attribute(QGeoPositionInfo::HorizontalAccuracy);
        log(QString("Location accuracy is %1 m").arg(haMeters));
    } else {
        log("Location updated, but not valid");
    }

    if (!m_daemonEnabled) {
        deleteGPS();
        return;
    }

    if(gpsPos.isValid()) {
        m_YougeoPosInfo = gpsPos;

        if (haMeters < m_accuracy && haMeters != 0) {

            emit gpsLocationReceived();

            if (!m_keepGpsRunning) {
                deleteGPS();
                log(QString("GPS stopped. Accuracy was %1 m").arg(haMeters));
            }
            // Is there location request?
            if (!m_askingLocation.isEmpty()) {
                // Send location response SMS
                m_message->sendLocationSMS("RES:", m_YougeoPosInfo, m_askingLocation);
                log(QString("SMS sent to number %1").arg(m_askingLocation));
                // Reset position and requester
                reset();
            }
        }
    }
}
예제 #14
0
void TRMainWindow::newLocationInfoReceived(const QGeoPositionInfo positionInfo)
{
    QGeoCoordinate currentCoords = positionInfo.coordinate();
    if(m_lastKnownPosition || !(currentCoords == *m_lastKnownPosition))
    {
        // We need to write to the file, let's initialize it
        if(m_outputKMLFile == NULL)
        {
            // File initialization
            QString timeStamp = positionInfo.timestamp().toString(Qt::ISODate);
            QString fileTimeStamp = positionInfo.timestamp().toString("hhmmssddMMyy");
            m_outputKMLFile = new QFile("c://Data//trackroute_"+fileTimeStamp+".kml");
            m_outputKMLFile->open(QIODevice::WriteOnly | QIODevice::Text);
            // File writer initialization
            if(m_kmlFileWriter == NULL)
            {
                // Header
                m_kmlFileWriter = new QXmlStreamWriter(m_outputKMLFile);
                m_kmlFileWriter->writeStartDocument();
                m_kmlFileWriter->writeNamespace("http://www.opengis.net/kml/2.2","kml");
                // Document
                m_kmlFileWriter->writeStartElement("Document");
                m_kmlFileWriter->writeTextElement("name","TrackRoute Path File");
                m_kmlFileWriter->writeTextElement("description","Pathfile generated by Trackroute on: "+timeStamp);
                // Style
                m_kmlFileWriter->writeStartElement("Style");
                m_kmlFileWriter->writeAttribute("id","yellowLineGreenPoly");
                // LineStyle
                m_kmlFileWriter->writeStartElement("LineStyle");
                m_kmlFileWriter->writeTextElement("color","7f00ffff");
                m_kmlFileWriter->writeTextElement("width","4");
                m_kmlFileWriter->writeEndElement();
                // PolyStyle
                m_kmlFileWriter->writeStartElement("PolyStyle");
                m_kmlFileWriter->writeTextElement("color","7f00ff00");
                m_kmlFileWriter->writeEndElement();
                // End Style
                m_kmlFileWriter->writeEndElement();
                // Placemark
                m_kmlFileWriter->writeStartElement("Placemark");
                m_kmlFileWriter->writeTextElement("name","TrackRoute Path "+timeStamp);
                m_kmlFileWriter->writeTextElement("description","Path generated by Trackroute on: "+timeStamp);
                m_kmlFileWriter->writeTextElement("styleUrl","#yellowLineGreenPoly");
                // LineString
                m_kmlFileWriter->writeStartElement("LineString");
                m_kmlFileWriter->writeTextElement("extrude","1");
                m_kmlFileWriter->writeTextElement("tessellate","1");
                m_kmlFileWriter->writeTextElement("altitudeMode","absolute");
                // Coordinates
                m_kmlFileWriter->writeStartElement("coordinates");
            }
        }

        // Update data
        m_numberOfUpdatesReceived++;
        m_currentSpeed = positionInfo.attribute(QGeoPositionInfo::GroundSpeed);
        m_currentSpeed = m_currentSpeed > 0 ? m_currentSpeed:0;
        m_totalSpeed += m_currentSpeed;
        m_averageSpeed = m_totalSpeed / m_numberOfUpdatesReceived;
        QString coordString = currentCoords.toString();

        // Update UI
        ui->latLonDataLabel->setText(coordString.left(coordString.lastIndexOf(",")));
        ui->altitudeDataLabel->setText(QString::number(currentCoords.altitude())+" m");
        ui->wptNumberDataLabel->setText(QString::number(m_numberOfUpdatesReceived));
        ui->currentSpdDataLabel->setText(QString::number(m_currentSpeed)+" km/h");
        ui->averageSpdDataLabel->setText(QString::number(m_averageSpeed)+" km/h");

        // Write to the KML file
        QString locationData = QString::number(currentCoords.latitude()).append(",").append(QString::number(currentCoords.longitude()))
                               .append(",").append(QString::number(currentCoords.altitude())).append(" ");
        m_kmlFileWriter->writeCharacters(locationData);
        m_outputKMLFile->flush();
    }
    m_lastKnownPosition = &currentCoords;
}
예제 #15
0
void QDeclarativePosition::setPosition(const QGeoPositionInfo &info)
{
    // timestamp
    const QDateTime pTimestamp = m_info.timestamp();
    const QDateTime timestamp = info.timestamp();
    bool emitTimestampChanged = pTimestamp != timestamp;

    // coordinate
    const QGeoCoordinate pCoordinate = m_info.coordinate();
    const QGeoCoordinate coordinate = info.coordinate();
    bool emitCoordinateChanged = pCoordinate != coordinate;
    bool emitLatitudeValidChanged = exclusiveNaN(pCoordinate.latitude(), coordinate.latitude());
    bool emitLongitudeValidChanged = exclusiveNaN(pCoordinate.longitude(), coordinate.longitude());
    bool emitAltitudeValidChanged = exclusiveNaN(pCoordinate.altitude(), coordinate.altitude());

    // direction
    const qreal pDirection = m_info.attribute(QGeoPositionInfo::Direction);
    const qreal direction = info.attribute(QGeoPositionInfo::Direction);
    bool emitDirectionChanged = !equalOrNaN(pDirection, direction);
    bool emitDirectionValidChanged = exclusiveNaN(pDirection, direction);

    // ground speed
    const qreal pSpeed = m_info.attribute(QGeoPositionInfo::GroundSpeed);
    const qreal speed = info.attribute(QGeoPositionInfo::GroundSpeed);
    bool emitSpeedChanged = !equalOrNaN(pSpeed, speed);
    bool emitSpeedValidChanged = exclusiveNaN(pSpeed, speed);

    // vertical speed
    const qreal pVerticalSpeed = m_info.attribute(QGeoPositionInfo::VerticalSpeed);
    const qreal verticalSpeed = info.attribute(QGeoPositionInfo::VerticalSpeed);
    bool emitVerticalSpeedChanged = !equalOrNaN(pVerticalSpeed, verticalSpeed);
    bool emitVerticalSpeedValidChanged = exclusiveNaN(pVerticalSpeed, verticalSpeed);

    // magnetic variation
    const qreal pMagneticVariation = m_info.attribute(QGeoPositionInfo::MagneticVariation);
    const qreal magneticVariation = info.attribute(QGeoPositionInfo::MagneticVariation);
    bool emitMagneticVariationChanged = !equalOrNaN(pMagneticVariation, magneticVariation);
    bool emitMagneticVariationValidChanged = exclusiveNaN(pMagneticVariation, magneticVariation);

    // horizontal accuracy
    const qreal pHorizontalAccuracy = m_info.attribute(QGeoPositionInfo::HorizontalAccuracy);
    const qreal horizontalAccuracy = info.attribute(QGeoPositionInfo::HorizontalAccuracy);
    bool emitHorizontalAccuracyChanged = !equalOrNaN(pHorizontalAccuracy, horizontalAccuracy);
    bool emitHorizontalAccuracyValidChanged = exclusiveNaN(pHorizontalAccuracy, horizontalAccuracy);

    // vertical accuracy
    const qreal pVerticalAccuracy = m_info.attribute(QGeoPositionInfo::VerticalAccuracy);
    const qreal verticalAccuracy = info.attribute(QGeoPositionInfo::VerticalAccuracy);
    bool emitVerticalAccuracyChanged = !equalOrNaN(pVerticalAccuracy, verticalAccuracy);
    bool emitVerticalAccuracyValidChanged = exclusiveNaN(pVerticalAccuracy, verticalAccuracy);

    m_info = info;

    if (emitTimestampChanged)
        emit timestampChanged();
    if (emitCoordinateChanged)
        emit coordinateChanged();
    if (emitLatitudeValidChanged)
        emit latitudeValidChanged();
    if (emitLongitudeValidChanged)
        emit longitudeValidChanged();
    if (emitAltitudeValidChanged)
        emit altitudeValidChanged();
    if (emitDirectionChanged)
        emit directionChanged();
    if (emitDirectionValidChanged)
        emit directionValidChanged();
    if (emitSpeedChanged)
        emit speedChanged();
    if (emitSpeedValidChanged)
        emit speedValidChanged();
    if (emitVerticalSpeedChanged)
        emit verticalSpeedChanged();
    if (emitVerticalSpeedValidChanged)
        emit verticalSpeedValidChanged();
    if (emitHorizontalAccuracyChanged)
        emit horizontalAccuracyChanged();
    if (emitHorizontalAccuracyValidChanged)
        emit horizontalAccuracyValidChanged();
    if (emitVerticalAccuracyChanged)
        emit verticalAccuracyChanged();
    if (emitVerticalAccuracyValidChanged)
        emit verticalAccuracyValidChanged();
    if (emitMagneticVariationChanged)
        emit magneticVariationChanged();
    if (emitMagneticVariationValidChanged)
        emit magneticVariationValidChanged();
}
예제 #16
0
void TestQGeoPositionInfoSource::lastKnownPosition()
{
    CHECK_SOURCE_VALID;
    QFETCH(int, positioningMethod);
    QFETCH(bool, lastKnownPositionArgument);
    QFETCH(bool, positionValid);

#if defined(Q_OS_SYMBIAN)
    QSKIP("Real GPS not suitable for autotesting, skipping the test.", SkipAll);
#endif
    QGeoPositionInfoSource::PositioningMethods method
            = static_cast<QGeoPositionInfoSource::PositioningMethods>(positioningMethod);

    if ((m_source->supportedPositioningMethods() & method) == 0)
        QSKIP("Not a supported positioning method for this position source", SkipSingle);

    m_source->setPreferredPositioningMethods(method);

    QSignalSpy spy(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&)));
    QSignalSpy timeout(m_source, SIGNAL(updateTimeout()));
    int time_out = 7000;
    m_source->setUpdateInterval(time_out);
    m_source->startUpdates();

    // Use QEventLoop instead of qWait() to ensure we stop as soon as a
    // position is emitted (otherwise the lastKnownPosition() may have
    // changed by the time it is checked)
    QEventLoop loop;
    QTimer timer;
    timer.setInterval(9500);
    connect(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&)),
            &loop, SLOT(quit()));
    connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
    timer.start();
    loop.exec();

    EXPECT_FAIL_WINCE_SEE_MOBILITY_337_ABORT;

    QVERIFY((spy.count() > 0) && (timeout.count() == 0));

    QList<QVariant> list = spy.takeFirst();
    QGeoPositionInfo info;
    info = list.at(0).value<QGeoPositionInfo>();
    QGeoPositionInfo lastPositioninfo;
    lastPositioninfo = m_source->lastKnownPosition(lastKnownPositionArgument);
 
    QCOMPARE(lastPositioninfo.isValid(), positionValid);

    if (positionValid) {
        QCOMPARE(info.coordinate(), lastPositioninfo.coordinate());
        QCOMPARE(info.timestamp(), lastPositioninfo.timestamp());

        QCOMPARE(info.hasAttribute(QGeoPositionInfo::HorizontalAccuracy),
                 lastPositioninfo.hasAttribute(QGeoPositionInfo::HorizontalAccuracy));

        if (info.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)) {
            bool isNaN1 =  qIsNaN(info.attribute(QGeoPositionInfo::HorizontalAccuracy));
            bool isNaN2 =  qIsNaN(lastPositioninfo.attribute(QGeoPositionInfo::HorizontalAccuracy));
            QCOMPARE(isNaN1, isNaN2);
            if (!isNaN1) {
                QCOMPARE(qFuzzyCompare(info.attribute(QGeoPositionInfo::HorizontalAccuracy),
                                       lastPositioninfo.attribute(QGeoPositionInfo::HorizontalAccuracy)), TRUE);
            }
        }

        QCOMPARE(info.hasAttribute(QGeoPositionInfo::VerticalAccuracy),
                 lastPositioninfo.hasAttribute(QGeoPositionInfo::VerticalAccuracy));

        if (info.hasAttribute(QGeoPositionInfo::VerticalAccuracy)) {
            bool isNaN1 =  qIsNaN(info.attribute(QGeoPositionInfo::VerticalAccuracy));
            bool isNaN2 =  qIsNaN(lastPositioninfo.attribute(QGeoPositionInfo::VerticalAccuracy));
            QCOMPARE(isNaN1, isNaN2);
            if (!isNaN1) {
                QCOMPARE(qFuzzyCompare(info.attribute(QGeoPositionInfo::VerticalAccuracy),
                                       lastPositioninfo.attribute(QGeoPositionInfo::VerticalAccuracy)), TRUE);
            }
        }
    }

    m_source->stopUpdates();
}