bool QGeoCodeParser::parsePlace(QGeoPlace *place)
{
    Q_ASSERT(m_reader->isStartElement() && (m_reader->name() == "place" || m_reader->name() == "addressparts"));

    if (m_reader->name() == "place") {
        QGeoBoundingBox bounds;
        if (!parseBoundingBox(&bounds,m_reader->attributes().value("boundingbox").toString()))
            return false;
        place->setViewport(bounds);
        place->setCoordinate(
                QGeoCoordinate(m_reader->attributes().value("lat").toString().toDouble(),
                               m_reader->attributes().value("lon").toString().toDouble()) );
    }

    QGeoAddress address;
    m_reader->readNext();
    while (!(m_reader->tokenType() == QXmlStreamReader::EndElement &&  (m_reader->name() == "place" || m_reader->name() == "addressparts"))) {
        if (m_reader->tokenType() == QXmlStreamReader::StartElement) {
            if (m_reader->name() == "house") {
            } else if (m_reader->name() == "road") {
                address.setStreet(m_reader->readElementText());
            } else if (m_reader->name() == "village") {
                address.setDistrict(m_reader->readElementText());
            } else if (m_reader->name() == "state") {
                address.setState(m_reader->readElementText());
            } else if (m_reader->name() == "town") {
            } else if (m_reader->name() == "city") {
                address.setCity(m_reader->readElementText());
            } else if (m_reader->name() == "county") {
                address.setCounty(m_reader->readElementText());
            } else if (m_reader->name() == "postcode") {
                address.setPostcode(m_reader->readElementText());
            } else if (m_reader->name() == "country") {
                address.setCountry(m_reader->readElementText());
            } else if (m_reader->name() == "country_code") {
                address.setCountryCode(m_reader->readElementText());
            } else {
                m_reader->skipCurrentElement();
            }
        }
        m_reader->readNext();
    }
    place->setAddress(address);
    return true;
}
Esempio n. 2
0
bool QLandmarkFileHandlerLmx::readAddressInfo(QLandmark &landmark)
{
    /*
    <xsd:complexType name="addressInfoType">
        <xsd:all>
            <xsd:element name="country" type="xsd:string" minOccurs="0" />
            <xsd:element name="countryCode" minOccurs="0">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:token">
                        <xsd:length value="2"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
            <xsd:element name="state" type="xsd:string" minOccurs="0" />
            <xsd:element name="county" type="xsd:string" minOccurs="0" />
            <xsd:element name="city" type="xsd:string" minOccurs="0" />
            <xsd:element name="district" type="xsd:string" minOccurs="0" />
            <xsd:element name="postalCode" type="xsd:string" minOccurs="0" />
            <xsd:element name="crossing1" type="xsd:string" minOccurs="0" />
            <xsd:element name="crossing2" type="xsd:string" minOccurs="0" />
            <xsd:element name="street" type="xsd:string" minOccurs="0" />
            <xsd:element name="buildingName" type="xsd:string" minOccurs="0" />
            <xsd:element name="buildingZone" type="xsd:string" minOccurs="0" />
            <xsd:element name="buildingFloor" type="xsd:string" minOccurs="0" />
            <xsd:element name="buildingRoom" type="xsd:string" minOccurs="0" />
            <xsd:element name="extension" type="xsd:string" minOccurs="0" />
            <xsd:element name="phoneNumber" type="xsd:string" minOccurs="0" />
        </xsd:all>
    </xsd:complexType>
    */

    Q_ASSERT(m_reader->isStartElement()
             && (m_reader->name() == "addressInfo"));

    QHash<QString, int> counts;
    counts["country"] = 0;
    counts["countryCode"] = 0;
    counts["state"] = 0;
    counts["county"] = 0;
    counts["city"] = 0;
    counts["district"] = 0;
    counts["postalCode"] = 0;
    counts["crossing1"] = 0;
    counts["crossing2"] = 0;
    counts["street"] = 0;
    counts["buildingName"] = 0;
    counts["buildingZone"] = 0;
    counts["buildingFloor"] = 0;
    counts["buildingRoom"] = 0;
    counts["extension"] = 0;
    counts["phoneNumber"] = 0;

    QGeoAddress address;

    while (m_reader->readNextStartElement()) {
        QString name = m_reader->name().toString();
        if (counts.keys().contains(name)) {
            if (counts.value(name) == 1) {
                m_reader->raiseError(QString("The element \"addressInfo\" did not expect more then one occurrence of the child element named \"%1\".").arg(m_reader->name().toString()));
                return false;
            }
            counts[name] = 1;

            if (name == "county") {
                address.setCounty(m_reader->readElementText());
            } else if (name == "country") {
                address.setCountry(m_reader->readElementText());
            } else if (name == "state") {
                address.setState(m_reader->readElementText());
            } else if (name == "city") {
                address.setCity(m_reader->readElementText());
            } else if (name == "district") {
                address.setDistrict(m_reader->readElementText());
            } else if (name == "postalCode") {
                address.setPostcode(m_reader->readElementText());
            } else if (name == "street") {
                QString street = m_reader->readElementText();
                address.setStreet(street);
            } else if (name == "phoneNumber") {
                landmark.setPhoneNumber(m_reader->readElementText());
            } else {
                m_reader->skipCurrentElement();
            }
        } else {
            m_reader->raiseError(QString("The element \"addressInfo\" did not expect a child element named \"%1\".").arg(m_reader->name().toString()));
            return false;
        }
    }

    landmark.setAddress(address);

    return true;
}