Exemplo n.º 1
0
void Navigator::on_addressSearchFinished()
{
    if (addressReply->places().size() <= 0) {
        addressReply->deleteLater();
        return;
    }

    QGeoPlace place = addressReply->places().at(0);

    QList<QGeoCoordinate> waypoints = request.waypoints();
    waypoints.append(place.coordinate());
    request.setWaypoints(waypoints);

    routeReply = routingManager->calculateRoute(request);
    if (routeReply->isFinished()) {
        on_routingFinished();
    } else {
        connect(routeReply, SIGNAL(error(QGeoRouteReply::Error,QString)),
                this, SIGNAL(routingError(QGeoRouteReply::Error,QString)));
        connect(routeReply, SIGNAL(finished()),
                this, SLOT(on_routingFinished()));
    }

    endMarker = new Marker(Marker::EndMarker);
    endMarker->setCoordinate(place.coordinate());
    endMarker->setAddress(place.address());
    endMarker->setName("Destination");
    mapsWidget->map()->addMapObject(endMarker);

    addressReply->deleteLater();
}
QDeclarativeGeoPlace::QDeclarativeGeoPlace(const QGeoPlace& place, QObject* parent) :
        QObject(parent),
        m_declarativeBox(place.viewport(), this),
        m_declarativeCoordinate(place.coordinate(), this),
        m_declarativeAddress(place.address(), this)
{
}
QVariant QDeclarativeGeocodeModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();

    if (index.row() > places().count())
        return QVariant();

    QGeoPlace place = places().at(index.row());

    if (role == Qt::DisplayRole)
        return place.coordinate().toString();

    return QDeclarativeGeoSearchModel::data(index, role);
}
QVariant QDeclarativeReverseGeocodeModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();

    if (index.row() > places().count())
        return QVariant();

    QGeoPlace place = places().at(index.row());

    if (role == Qt::DisplayRole) {
        QGeoAddress address = place.address();

        QStringList addressStrings;
        if (!address.street().isEmpty())
            addressStrings << address.street();
        if (!address.city().isEmpty())
            addressStrings << address.city();

        QStringList stateLine;
        if (!address.state().isEmpty())
            stateLine << address.state();
        if (!address.postcode().isEmpty())
            stateLine << address.postcode();
        if (!address.country().isEmpty())
            stateLine << address.country();

        QString stateString = stateLine.join(" ");

        if (!stateString.isEmpty())
            addressStrings << stateString;

        return addressStrings.join(", ");
    }

    return QDeclarativeGeoSearchModel::data(index, role);
}
void QDeclarativeGeoPlace::setPlace(const QGeoPlace& place)
{
    m_declarativeBox.setBox(place.viewport());
    m_declarativeCoordinate.setCoordinate(place.coordinate());
    m_declarativeAddress.setAddress(place.address());
}