Ejemplo n.º 1
0
bool QGeoRouteXmlParser::parseBoundingBox(QGeoBoundingBox &bounds)
{
    Q_ASSERT(m_reader->isStartElement() && m_reader->name() == "BoundingBox");

    QGeoCoordinate tl;
    QGeoCoordinate br;

    m_reader->readNext();
    while (!(m_reader->tokenType() == QXmlStreamReader::EndElement && m_reader->name() == "BoundingBox")) {
        if (m_reader->tokenType() == QXmlStreamReader::StartElement) {
            if (m_reader->name() == "TopLeft") {
                QGeoCoordinate coordinates;
                if (parseCoordinates(coordinates))
                    tl = coordinates;
            } else if (m_reader->name() == "BottomRight") {
                QGeoCoordinate coordinates;
                if (parseCoordinates(coordinates))
                    br = coordinates;
            } else {
                m_reader->skipCurrentElement();
            }
        }
        m_reader->readNext();
    }

    if (tl.isValid() && br.isValid()) {
        bounds = QGeoBoundingBox(tl, br);
        return true;
    }

    return false;
}
/*!
    \internal
*/
void QDeclarativeRectangleMapItem::dragEnded()
{
    QPointF newTopLeftPoint = QPointF(x(),y());
    QGeoCoordinate newTopLeft = map()->screenPositionToCoordinate(newTopLeftPoint, false);
    if (newTopLeft.isValid()) {
        // calculate new geo width while checking for dateline crossing
        const double lonW = bottomRight_.longitude() > topLeft_.longitude() ?
                    bottomRight_.longitude() - topLeft_.longitude() :
                    bottomRight_.longitude() + 360 - topLeft_.longitude();
        const double latH = qAbs(bottomRight_.latitude() - topLeft_.latitude());
        QGeoCoordinate newBottomRight;
        // prevent dragging over valid min and max latitudes
        if (QLocationUtils::isValidLat(newTopLeft.latitude() - latH)) {
            newBottomRight.setLatitude(newTopLeft.latitude() - latH);
        } else {
            newBottomRight.setLatitude(QLocationUtils::clipLat(newTopLeft.latitude() - latH));
            newTopLeft.setLatitude(newBottomRight.latitude() + latH);
        }
        // handle dateline crossing
        newBottomRight.setLongitude(QLocationUtils::wrapLong(newTopLeft.longitude() + lonW));
        newBottomRight.setAltitude(newTopLeft.altitude());
        topLeft_ = newTopLeft;
        bottomRight_ = newBottomRight;
        geometry_.setPreserveGeometry(true, newTopLeft);
        borderGeometry_.setPreserveGeometry(true, newTopLeft);
        geometry_.markSourceDirty();
        borderGeometry_.markSourceDirty();
        updateMapItem();
        emit topLeftChanged(topLeft_);
        emit bottomRightChanged(bottomRight_);
    }
}
/*!
    \internal
*/
void QDeclarativeCircleMapItem::dragEnded()
{
    QPointF newPoint = QPointF(x(),y()) + QPointF(width(), height()) / 2;
    QGeoCoordinate newCoordinate = map()->screenPositionToCoordinate(newPoint, false);
    if (newCoordinate.isValid())
        setCenter(newCoordinate);
}
void PointInPolygonWidget::positionUpdated(const QGeoPositionInfo &info)
{
    QGeoPositionInfo pos_info = info;
    QGeoCoordinate pos = pos_info.coordinate();

    if (pos.isValid()) {

        ui->xNewPoint->setValue(pos.latitude());
        ui->yNewPoint->setValue(pos.longitude());

        ui->xPoint->setValue(pos.latitude());
        ui->yPoint->setValue(pos.longitude());

        double dist = 0;
        if (is_first_distance_) {
            dist_acc_ = 0;
            is_first_distance_ = false;
        } else {
            if (std::fabs(pos.altitude()) < 1e-3) {
                pos.setAltitude(last_position_.coordinate().altitude());
                pos_info.setCoordinate(pos);
            }
            dist = pos_info.coordinate().distanceTo(last_position_.coordinate());
            if (dist > 10) {
                dist_acc_ += dist;
            }
        }
        last_position_ = pos_info;
    }
}
Ejemplo n.º 5
0
void QDeclarativeGeoRoute::setPath(const QJSValue &value)
{
    if (!value.isArray())
        return;

    QList<QGeoCoordinate> pathList;
    quint32 length = value.property(QStringLiteral("length")).toUInt();
    for (quint32 i = 0; i < length; ++i) {
        bool ok;
        QGeoCoordinate c = parseCoordinate(value.property(i), &ok);

        if (!ok || !c.isValid()) {
            qmlInfo(this) << "Unsupported path type";
            return;
        }

        pathList.append(c);
    }

    if (route_.path() == pathList)
        return;

    route_.setPath(pathList);

    emit pathChanged();
}
void QDeclarativePolylineMapItem::setPath(const QJSValue &value)
{
    if (!value.isArray())
        return;

    QList<QGeoCoordinate> pathList;
    quint32 length = value.property(QStringLiteral("length")).toUInt();
    for (quint32 i = 0; i < length; ++i) {
        bool ok;
        QGeoCoordinate c = parseCoordinate(value.property(i), &ok);

        if (!ok || !c.isValid()) {
            qmlInfo(this) << "Unsupported path type";
            return;
        }

        pathList.append(c);
    }

    if (path_ == pathList)
        return;

    path_ = pathList;

    geometry_.markSourceDirty();
    updateMapItem();
    emit pathChanged();
}
Ejemplo n.º 7
0
/*!
  Extends the circle to include \a coordinate
*/
void QGeoCirclePrivate::extendShape(const QGeoCoordinate &coordinate)
{
    if (!isValid() || !coordinate.isValid() || contains(coordinate))
        return;

    radius = center.distanceTo(coordinate);
}
void QGeoAreaMonitorPolling::setCenter(const QGeoCoordinate& coordinate)
{
    if (coordinate.isValid()) {
        QGeoAreaMonitor::setCenter(coordinate);
        checkStartStop();
    }
}
Ejemplo n.º 9
0
void QDeclarativePosition::setCoordinate(const QGeoCoordinate &coordinate)
{
    if (m_coordinate == coordinate)
        return;

    m_coordinate = coordinate;

    if (coordinate.type() == QGeoCoordinate::Coordinate3D && !m_altitudeValid) {
        m_altitudeValid = true;
        emit altitudeValidChanged();
    } else if (m_altitudeValid) {
        m_altitudeValid = false;
        emit altitudeValidChanged();
    }
    if (coordinate.isValid()) {
        if (!m_longitudeValid) {
            m_longitudeValid = true;
            emit longitudeValidChanged();
        }
        if (!m_latitudeValid) {
            m_latitudeValid = true;
            emit latitudeValidChanged();
        }
    } else {
        if (m_longitudeValid) {
            m_longitudeValid = false;
            emit longitudeValidChanged();
        }
        if (m_latitudeValid) {
            m_latitudeValid = false;
            emit latitudeValidChanged();
        }
    }
    emit coordinateChanged();
}
static bool addAtForBoundingArea(const QGeoShape &area,
                                 QUrlQuery *queryItems)
{
    QGeoCoordinate center;
    switch (area.type()) {
    case QGeoShape::RectangleType:
        center = QGeoRectangle(area).center();
        break;
    case QGeoShape::CircleType:
        center = QGeoCircle(area).center();
        break;
    case QGeoShape::UnknownType:
        break;
    }

    if (!center.isValid()) {
        return false;
    } else {
        queryItems->addQueryItem(QLatin1String("at"),
                                 QString::number(center.latitude()) +
                                 QLatin1Char(',') +
                                 QString::number(center.longitude()));
        return true;
    }
}
Ejemplo n.º 11
0
/*!
    Returns whether the coordinate \a coordinate is contained within this
    bounding box.
*/
bool QGeoBoundingBox::contains(const QGeoCoordinate &coordinate) const
{

    if (!isValid() || !coordinate.isValid())
        return false;

    double left = d_ptr->topLeft.longitude();
    double right = d_ptr->bottomRight.longitude();
    double top = d_ptr->topLeft.latitude();
    double bottom = d_ptr->bottomRight.latitude();

    double lon = coordinate.longitude();
    double lat = coordinate.latitude();

    if (lat > top)
        return false;
    if (lat < bottom)
        return false;

    if ((lat == 90.0) && (top == 90.0))
        return true;

    if ((lat == -90.0) && (bottom == -90.0))
        return true;

    if (left <= right) {
        if ((lon < left) || (lon > right))
            return false;
    } else {
        if ((lon < left) && (lon > right))
            return false;
    }

    return true;
}
Ejemplo n.º 12
0
void MapBox::captureCoordinates()
{
    QGeoCoordinate coords = m_mapWidget->screenPositionToCoordinate(m_lastClicked);

    if (!coords.isValid())
        return;

    m_latitudeEdit->setText(QString::number(coords.latitude()));
    m_longitudeEdit->setText(QString::number(coords.longitude()));
}
Ejemplo n.º 13
0
QGeoCoordinate QExiv2::geoCoordinate() const
{
	// Prefer XMP
	QGeoCoordinate gc = xmpGeoCoordinate();
	if (!gc.isValid()) {
		// Fallback to exif
		gc = exifGeoCoordinate();
	}
	return gc;
}
Ejemplo n.º 14
0
bool QGeoCirclePrivate::contains(const QGeoCoordinate &coordinate) const
{
    if (!isValid() || !coordinate.isValid())
        return false;

    // see QTBUG-41447 for details
    qreal distance = center.distanceTo(coordinate);
    if (qFuzzyCompare(distance, radius) || distance <= radius)
        return true;

    return false;
}
Ejemplo n.º 15
0
QGeoCoordinate GasInfoSettings::defaultHostLocation() const
{
    QByteArray ba = value(defaultHostLocationKey).toByteArray();
    QDataStream in(&ba, QIODevice::ReadOnly);
    QGeoCoordinate location;

    in >> location;

    if (!location.isValid())
        return QGeoCoordinate(39.903924, 116.391432, 0);
    else
        return location;
}
/*!
    \internal
*/
void QDeclarativeCircleMapItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
    if (updatingGeometry_ || newGeometry == oldGeometry) {
        QDeclarativeGeoMapItemBase::geometryChanged(newGeometry, oldGeometry);
        return;
    }

    QDoubleVector2D newPoint = QDoubleVector2D(x(),y()) + QDoubleVector2D(width(), height()) / 2;
    QGeoCoordinate newCoordinate = map()->itemPositionToCoordinate(newPoint, false);
    if (newCoordinate.isValid())
        setCenter(newCoordinate);

    // Not calling QDeclarativeGeoMapItemBase::geometryChanged() as it will be called from a nested
    // call to this function.
}
/*!
    \internal
*/
void QDeclarativeGeoMapQuickItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
    if (!mapAndSourceItemSet_ || updatingGeometry_ ||
        newGeometry.topLeft() == oldGeometry.topLeft()) {
        QDeclarativeGeoMapItemBase::geometryChanged(newGeometry, oldGeometry);
        return;
    }

    QGeoCoordinate newCoordinate = map()->itemPositionToCoordinate(QDoubleVector2D(x(), y()) + (scaleFactor() * QDoubleVector2D(anchorPoint_)), false);
    if (newCoordinate.isValid())
        setCoordinate(newCoordinate);

    // Not calling QDeclarativeGeoMapItemBase::geometryChanged() as it will be called from a nested
    // call to this function.
}
/*!
    \internal
*/
void QDeclarativePolylineMapItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
    if (updatingGeometry_ || newGeometry.topLeft() == oldGeometry.topLeft()) {
        QDeclarativeGeoMapItemBase::geometryChanged(newGeometry, oldGeometry);
        return;
    }

    QDoubleVector2D newPoint = QDoubleVector2D(x(),y()) + QDoubleVector2D(geometry_.firstPointOffset());
    QGeoCoordinate newCoordinate = map()->screenPositionToCoordinate(newPoint, false);
    if (newCoordinate.isValid()) {
        double firstLongitude = path_.at(0).longitude();
        double firstLatitude = path_.at(0).latitude();
        double minMaxLatitude = firstLatitude;
        // prevent dragging over valid min and max latitudes
        for (int i = 0; i < path_.count(); ++i) {
            double newLatitude = path_.at(i).latitude()
                    + newCoordinate.latitude() - firstLatitude;
            if (!QLocationUtils::isValidLat(newLatitude)) {
                if (qAbs(newLatitude) > qAbs(minMaxLatitude)) {
                    minMaxLatitude = newLatitude;
                }
            }
        }
        // calculate offset needed to re-position the item within map border
        double offsetLatitude = minMaxLatitude - QLocationUtils::clipLat(minMaxLatitude);
        for (int i = 0; i < path_.count(); ++i) {
            QGeoCoordinate coord = path_.at(i);
            // handle dateline crossing
            coord.setLongitude(QLocationUtils::wrapLong(coord.longitude()
                               + newCoordinate.longitude() - firstLongitude));
            coord.setLatitude(coord.latitude()
                              + newCoordinate.latitude() - firstLatitude - offsetLatitude);
            path_.replace(i, coord);
        }

        QGeoCoordinate leftBoundCoord = geometry_.geoLeftBound();
        leftBoundCoord.setLongitude(QLocationUtils::wrapLong(leftBoundCoord.longitude()
                           + newCoordinate.longitude() - firstLongitude));
        geometry_.setPreserveGeometry(true, leftBoundCoord);
        geometry_.markSourceDirty();
        updateMapItem();
        emit pathChanged();
    }

    // Not calling QDeclarativeGeoMapItemBase::geometryChanged() as it will be called from a nested
    // call to this function.
}
Ejemplo n.º 19
0
/*!
    \qmlproperty coordinate QtLocation::Map::center

    This property holds the coordinate which occupies the center of the
    mapping viewport. Invalid center coordinates are ignored.

    The default value is an arbitrary valid coordinate.
*/
void QDeclarativeGeoMap::setCenter(const QGeoCoordinate &center)
{
    if (!mappingManagerInitialized_ && center == center_)
        return;

    if (!center.isValid())
        return;

    center_ = center;

    if (center_.isValid() && mappingManagerInitialized_) {
        map_->mapController()->setCenter(center_);
        update();
    } else {
        emit centerChanged(center_);
    }
}
Ejemplo n.º 20
0
void QGeoMapController::pan(qreal dx, qreal dy)
{
    if (dx == 0 && dy == 0)
        return;
    QGeoCameraData cd = map_->cameraData();
    QGeoCoordinate coord = map_->itemPositionToCoordinate(
                                QDoubleVector2D(map_->width() / 2 + dx,
                                        map_->height() / 2 + dy));


    // keep altitude as it was
    coord.setAltitude(cd.center().altitude());
    if (coord.isValid()) {
        cd.setCenter(coord);
        map_->setCameraData(cd);
    }
}
Ejemplo n.º 21
0
/*!
    \qmlproperty coordinate QtLocation::Map::center

    This property holds the coordinate which occupies the center of the
    mapping viewport. Invalid center coordinates are ignored.

    The default value is an arbitrary valid coordinate.
*/
void QDeclarativeGeoMap::setCenter(const QGeoCoordinate &center)
{
    if (!m_mappingManagerInitialized && center == m_center)
        return;

    if (!center.isValid())
        return;

    m_center = center;

    if (m_center.isValid() && m_mappingManagerInitialized) {
        m_map->mapController()->setCenter(m_center);
        update();
    } else {
        emit centerChanged(m_center);
    }
}
Ejemplo n.º 22
0
void CurrentConditions::reqCurrCond(const QGeoCoordinate& position){
    /// Requests the current conditions data.

    if( position.isValid() ){

        QNetworkRequest request(QUrl(QString::fromStdString(std::string("http://forecast.weather.gov/MapClick.php?lat="
                                             + std::to_string(position.latitude())
                                             + "&lon="
                                             + std::to_string(position.longitude())
                                             + "&FcstType=json"))));
        request.setAttribute(QNetworkRequest::User, QVariant(ReqType::NOAA_JSON_FCAST_CURRCOND));

        m_nam->get(request);
    }
    // TODO if m_position is not valid.
    return;
}
Ejemplo n.º 23
0
void GpsPosition::timeout()
{
    double distance = 0;
    qDebug() << "\ntimeout\n\n";
    QGeoCoordinate coord = _location->lastKnownPosition(true).coordinate();
    qDebug() << "SAVED POSITION lat = " << _latitude << " lon = " << _longitude;
    qDebug() << "LAST POSITION lat = " << coord.latitude() << " lon = " << coord.longitude();
    if (coord.isValid()){
        distance = Core::DatabaseSqlite::calculate_distance(_latitude, _longitude,
                                                            coord.latitude(), coord.longitude());
        qDebug() << "distancd = " << distance;
        /* check distance between the last and found coordinates */
        if (distance > UPDATE_DISTANCE){
            /* distance more then UPDATE_DISTANCE km */
            emit findCoord(coord.latitude(), coord.longitude());
        }
    }
}
Ejemplo n.º 24
0
void GpsPosition::positionUpdated(QGeoPositionInfo info)
{
    double latitude, longitude;
    //qDebug() << "gps info " << info;
    QGeoCoordinate coord = info.coordinate();
    if (coord.isValid()){
        longitude = coord.longitude();
        latitude = coord.latitude();
        qDebug() << "lon = " << longitude << ", lat = " << latitude;
        if (_isUpdated){
            _location->stopUpdates();
            _isUpdated = false;
        }
        emit findCoord(latitude, longitude);

        /* set timer */
        startTimer();
    }
}
/*!
    \internal
*/
void QDeclarativePolygonMapItem::dragEnded()
{
    QPointF newPoint = QPointF(x(),y()) + geometry_.firstPointOffset();
    QGeoCoordinate newCoordinate = map()->screenPositionToCoordinate(newPoint, false);
    if (newCoordinate.isValid()) {
        double firstLongitude = path_.at(0).longitude();
        double firstLatitude = path_.at(0).latitude();
        double minMaxLatitude = firstLatitude;
        // prevent dragging over valid min and max latitudes
        for (int i = 0; i < path_.count(); ++i) {
            double newLatitude = path_.at(i).latitude()
                    + newCoordinate.latitude() - firstLatitude;
            if (!QLocationUtils::isValidLat(newLatitude)) {
                if (qAbs(newLatitude) > qAbs(minMaxLatitude)) {
                    minMaxLatitude = newLatitude;
                }
            }
        }
        // calculate offset needed to re-position the item within map border
        double offsetLatitude = minMaxLatitude - QLocationUtils::clipLat(minMaxLatitude);
        for (int i = 0; i < path_.count(); ++i) {
            QGeoCoordinate coord = path_.at(i);
            // handle dateline crossing
            coord.setLongitude(QLocationUtils::wrapLong(coord.longitude()
                               + newCoordinate.longitude() - firstLongitude));
            coord.setLatitude(coord.latitude()
                              + newCoordinate.latitude() - firstLatitude - offsetLatitude);

            path_.replace(i, coord);
        }

        QGeoCoordinate leftBoundCoord = geometry_.geoLeftBound();
        leftBoundCoord.setLongitude(QLocationUtils::wrapLong(leftBoundCoord.longitude()
                           + newCoordinate.longitude() - firstLongitude));
        geometry_.setPreserveGeometry(true, leftBoundCoord);
        borderGeometry_.setPreserveGeometry(true, leftBoundCoord);
        geometry_.markSourceDirty();
        borderGeometry_.markSourceDirty();
        updateMapItem();
        emit pathChanged();
    }
}
void VerticalProfilePresenter::updateMission()
{
    this->invokeViewMethod(PROPERTY(clearWaypoints));

    dto::MissionPtr mission = m_service->mission(m_missionId);
    if (mission.isNull() || mission->count() < 1) return;

    QGeoCoordinate lastPosition;
    int distance = 0;
    int homeAltitude = 0;
    int minAltitude = INT_MAX;
    int maxAltitude = INT_MIN;

    for (const dto::MissionItemPtr& item: m_service->missionItems(mission->id()))
    {
        if (!item->isAltitudedItem()) continue;

        if (item->sequence() == 0) homeAltitude = item->altitude();

        if (item->isPositionatedItem())
        {
            if (item->coordinate().isValid() && lastPosition.isValid())
            {
                distance += lastPosition.distanceTo(item->coordinate());
            }
            lastPosition = item->coordinate();
        }

        int altitude = item->isAltitudeRelative() ? homeAltitude + item->altitude() : item->altitude();

        if (altitude < minAltitude) minAltitude = altitude;
        if (altitude > maxAltitude) maxAltitude = altitude;

        this->invokeViewMethod(PROPERTY(appendWaypoint), distance, altitude);
    }

    this->setViewProperty(PROPERTY(minDistance), 0);
    this->setViewProperty(PROPERTY(maxDistance), distance);
    this->setViewProperty(PROPERTY(minAltitude), minAltitude);
    this->setViewProperty(PROPERTY(maxAltitude), maxAltitude);
}
Ejemplo n.º 27
0
void ModelIndexLayer::render(QPainter& painter)
{
    if (mItemModel == NULL)
    {
        qDebug() << "Model == NULL";
        // Nothing to do. return.
        return;
    }

    foreach(QModelIndex index, mCulled)
    {
        QGeoCoordinate coord = mItemModel->data(index, ModelIndexLayer::GeoCoordinateRole).value<QGeoCoordinate>();

        if (!coord.isValid())
            continue;

        // prepare the viewport for the delegate
        QRect vp = markerPosition(coord);

        painter.save();
        painter.setClipRect(vp);
        painter.setWindow(QRect(0, 0, vp.width(), vp.height()));
        painter.setViewport(vp);

        MarkerInfo markerInfo;
        markerInfo.coord      = coord;
        markerInfo.modelIndex = index;
        markerInfo.x          = vp.left();
        markerInfo.y          = vp.top();
        markerInfo.width      = vp.width();
        markerInfo.height     = vp.height();

        if (mSelectionModel != NULL)
            markerInfo.markerState = mSelectionModel->selection().contains(index)
                ? MarkerInfo::MarkerStateSelected : MarkerInfo::MarkerStateNone;

        QVariant v = mItemModel->data(index, ModelIndexLayer::DataRole);
        mDelegate->paint(painter, markerInfo, v);
        painter.restore();
    }     // else skip, this coord is not in view
/*!
    \internal
*/
void QDeclarativeRectangleMapItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
    if (updatingGeometry_ || newGeometry.topLeft() == oldGeometry.topLeft()) {
        QDeclarativeGeoMapItemBase::geometryChanged(newGeometry, oldGeometry);
        return;
    }

    QDoubleVector2D newTopLeftPoint = QDoubleVector2D(x(),y());
    QGeoCoordinate newTopLeft = map()->itemPositionToCoordinate(newTopLeftPoint, false);
    if (newTopLeft.isValid()) {
        // calculate new geo width while checking for dateline crossing
        const double lonW = bottomRight_.longitude() > topLeft_.longitude() ?
                    bottomRight_.longitude() - topLeft_.longitude() :
                    bottomRight_.longitude() + 360 - topLeft_.longitude();
        const double latH = qAbs(bottomRight_.latitude() - topLeft_.latitude());
        QGeoCoordinate newBottomRight;
        // prevent dragging over valid min and max latitudes
        if (QLocationUtils::isValidLat(newTopLeft.latitude() - latH)) {
            newBottomRight.setLatitude(newTopLeft.latitude() - latH);
        } else {
            newBottomRight.setLatitude(QLocationUtils::clipLat(newTopLeft.latitude() - latH));
            newTopLeft.setLatitude(newBottomRight.latitude() + latH);
        }
        // handle dateline crossing
        newBottomRight.setLongitude(QLocationUtils::wrapLong(newTopLeft.longitude() + lonW));
        newBottomRight.setAltitude(newTopLeft.altitude());
        topLeft_ = newTopLeft;
        bottomRight_ = newBottomRight;
        geometry_.setPreserveGeometry(true, newTopLeft);
        borderGeometry_.setPreserveGeometry(true, newTopLeft);
        markSourceDirtyAndUpdate();
        emit topLeftChanged(topLeft_);
        emit bottomRightChanged(bottomRight_);
    }

    // Not calling QDeclarativeGeoMapItemBase::geometryChanged() as it will be called from a nested
    // call to this function.
}
void QGeoAreaMonitorSimulator::setCenter(const QGeoCoordinate& coordinate)
{
    if (coordinate.isValid())
        QGeoAreaMonitor::setCenter(coordinate);
}