Пример #1
0
bool QLandmarkFileHandlerLmx::writeCoordinates(const QLandmark &landmark)
{
    m_writer->writeStartElement(m_ns, "coordinates");

    double lat = landmark.coordinate().latitude();
    double lon = landmark.coordinate().longitude();
    double alt = landmark.coordinate().altitude();

    if (qIsNaN(lat))
        m_writer->writeTextElement(m_ns, "latitude", "NaN");
    else
        m_writer->writeTextElement(m_ns, "latitude", QString::number(lat));

    if (qIsNaN(lon))
        m_writer->writeTextElement(m_ns, "longitude", "NaN");
    else
        m_writer->writeTextElement(m_ns, "longitude", QString::number(lon));

    if (!qIsNaN(alt))
        m_writer->writeTextElement(m_ns, "altitude", QString::number(alt));

    m_writer->writeEndElement();

    return true;
}
    void testFilterIntersection()
    {
        //test a negative match
        QLandmarkIntersectionFilter intersectionFilter;
        QLandmarkNameFilter nameFilter1("Sasuke");
        QLandmarkNameFilter nameFilter2("Kakashi");
        QLandmarkNameFilter nameFilter3("Itachi");

        QLandmark lm;
        lm.setName("Kakashi");

        intersectionFilter << nameFilter1 << nameFilter2 << nameFilter3;
        QVERIFY(!MockEngine::testFilter(intersectionFilter,lm));

        //test a positive match
        QLandmarkCategoryId cat1;
        cat1.setLocalId("konoha");
        cat1.setManagerUri("qtlandmarks:mock:");
        QLandmarkCategoryFilter categoryFilter(cat1);

        QLandmarkAttributeFilter attributeFilter;
        attributeFilter.setAttribute("description","sharingan");

        lm.setDescription("sharingan");
        lm.addCategoryId(cat1);

        intersectionFilter.clear();
        intersectionFilter << attributeFilter << categoryFilter << nameFilter2;

        QVERIFY(MockEngine::testFilter(intersectionFilter,lm));

        //test empty intersection filter
        intersectionFilter.clear();
        QVERIFY(!MockEngine::testFilter(intersectionFilter,lm));
    }
Пример #3
0
bool QLandmarkFileHandlerLmx::writeLandmark(const QLandmark &landmark)
{
    m_writer->writeStartElement(m_ns, "landmark");

    if (!landmark.name().isEmpty())
        m_writer->writeTextElement(m_ns, "name", landmark.name());

    if (!landmark.description().isEmpty())
        m_writer->writeTextElement(m_ns, "description", landmark.description());

    if (landmark.coordinate().isValid())
        if (!writeCoordinates(landmark))
            return false;

    if (landmark.radius() > 0)
        m_writer->writeTextElement(m_ns, "coverageRadius", QString::number(landmark.radius()));

    if (!writeAddressInfo(landmark))
        return false;

    if (!landmark.url().isEmpty())
        if (!writeMediaLink(landmark))
            return false;

    if (m_option != QLandmarkManager::ExcludeCategoryData) {
        for (int i = 0; i < landmark.categoryIds().size(); ++i) {
            if (!writeCategory(landmark.categoryIds().at(i)))
                return false;
        }
    }

    m_writer->writeEndElement();

    return true;
}
    void testFilterLandmarkId()
    {
        //test landmark id filter that matches
        QLandmarkId lmId1, lmId2, lmId3;
        lmId1.setLocalId("1");
        lmId1.setManagerUri("qtlandmarks:mock:");

        lmId2.setLocalId("2");
        lmId2.setManagerUri("qtlandmarks:mock:");

        lmId3.setLocalId("3");
        lmId3.setManagerUri("qtlandmarks:mock:");

        QLandmarkIdFilter idFilter;
        idFilter << lmId1 << lmId2 << lmId3;

        QLandmark lm;
        lm.setLandmarkId(lmId2);

        QVERIFY(MockEngine::testFilter(idFilter,lm));

        //test landmark id filter that doesn't match
        QLandmarkId lmId4;
        lmId4.setLocalId("4");
        lmId4.setManagerUri("qtlandmarks:mock:");

        lm.setLandmarkId(lmId4);
        QVERIFY(!MockEngine::testFilter(idFilter, lm));
    }
Пример #5
0
bool QLandmarkFileHandlerLmx::writeMediaLink(const QLandmark &landmark)
{
    //only write out URIs which are absolute in accordance the specification
    //for lmx 1.0
    if (isURIAbsolute(landmark.url().toString())) {
        m_writer->writeStartElement(m_ns, "mediaLink");
        m_writer->writeTextElement(m_ns, "url", landmark.url().toString());
        m_writer->writeEndElement();
    }

    return true;
}
/*!
    Convenience function that sets a single \a landmark to be removed.
    This function is the equivalent of calling setLandmarkIds()
    with the ID of \a landmark.
*/
void QLandmarkRemoveRequest::setLandmark(const QLandmark &landmark)
{
    Q_D(QLandmarkRemoveRequest);
    QMutexLocker ml(&d->mutex);
    d->landmarkIds.clear();
    d->landmarkIds.append(landmark.landmarkId());
}
Пример #7
0
bool QLandmarkFileHandlerLmx::writeAddressInfo(const QLandmark &landmark)
{
    QGeoAddress address = landmark.address();

    if (address.street().isEmpty()
            && address.city().isEmpty()
            && address.state().isEmpty()
            && address.country().isEmpty()
            && address.postcode().isEmpty()
            && landmark.phoneNumber().isEmpty())
        return true;

    m_writer->writeStartElement(m_ns, "addressInfo");

    if (!address.country().isEmpty())
        m_writer->writeTextElement(m_ns, "country", address.country());

    if (!address.state().isEmpty())
        m_writer->writeTextElement(m_ns, "state", address.state());

    if (!address.county().isEmpty())
        m_writer->writeTextElement(m_ns, "county", address.county());

    if (!address.city().isEmpty())
        m_writer->writeTextElement(m_ns, "city", address.city());

    if (!address.district().isEmpty())
        m_writer->writeTextElement(m_ns, "district", address.district());

    if (!address.postcode().isEmpty())
        m_writer->writeTextElement(m_ns, "postalCode", address.postcode());

    QString street;

    if (!address.street().isEmpty())
        street.append(address.street());

    if (!street.isEmpty())
        m_writer->writeTextElement(m_ns, "street", street);

    if (!landmark.phoneNumber().isEmpty())
        m_writer->writeTextElement(m_ns, "phoneNumber", landmark.phoneNumber());

    m_writer->writeEndElement();

    return true;
}
bool QLandmarkFileHandlerLmx::writeMediaLink(const QLandmark &landmark)
{
    m_writer->writeStartElement(m_ns, "mediaLink");
    m_writer->writeTextElement(m_ns, "url", landmark.url().toString());
    m_writer->writeEndElement();

    return true;
}
    void testFilterBox() {
        QLandmarkBoxFilter boxFilter(QGeoCoordinate(20,30),QGeoCoordinate(10,40));

        //landmark is in box
        QLandmark lm;
        lm.setCoordinate(QGeoCoordinate(15,35));
        QVERIFY(MockEngine::testFilter(boxFilter,lm));

        //landmark is outside box
        lm.setCoordinate(QGeoCoordinate(50,50));
        QVERIFY(!MockEngine::testFilter(boxFilter,lm));

        //test landmark inside box when box crosses dateline
        QGeoBoundingBox box;
        box.setTopLeft(QGeoCoordinate(20,170));
        box.setBottomRight(QGeoCoordinate(10,-170));
        boxFilter.setBoundingBox(box);

        lm.setCoordinate(QGeoCoordinate(15,-175));
        QVERIFY(MockEngine::testFilter(boxFilter, lm));

        lm.setCoordinate(QGeoCoordinate(15, 175));
        QVERIFY(MockEngine::testFilter(boxFilter, lm));


        //test landmark outside box when box crosses dateline
        lm.setCoordinate(QGeoCoordinate(15, 160));
        QVERIFY(!MockEngine::testFilter(boxFilter, lm));

        lm.setCoordinate(QGeoCoordinate(15, -160));
        QVERIFY(!MockEngine::testFilter(boxFilter, lm));
    }
    void cancelExport()
    {
        TestThread cancelThread;
        QLandmarkFileHandlerGpx handler(&(cancelThread.m_cancel));
        QLandmark lm;
        QList<QLandmark> lms;
        for (int i=0; i < 50000; ++i) {
            lm.setName(QString("LM%1").arg(0));
            lms.append(lm);
        }

        handler.setWaypoints(lms);
        cancelThread.start();
        QFile file(m_exportFile);
        QVERIFY(!handler.exportData(&file));
        QCOMPARE(handler.error(), QLandmarkManager::CancelError);
        cancelThread.wait();
    }
Пример #11
0
bool QLandmarkFileHandlerGpx::writeWaypoint(const QLandmark &landmark, const QString &elementName)
{
    double lat = landmark.coordinate().latitude();
    double lon = landmark.coordinate().longitude();

    QString latString;
    QString lonString;
    bool isInvalid = false;

    if (!qIsNaN(lat)) {
        if ((lat > 90.0 )| (lat < -90.0))
            isInvalid = true;
        latString = QString::number(lat);
    } else {
        latString = "NaN";
        isInvalid = true;
    }

    if (!qIsNaN(lon)) {
        if ((lon > 180.0) | (lon < -180.0))
            isInvalid = true;
        lonString = QString::number(lon);
    } else {
        lonString = "NaN";
        isInvalid = true;
    }

    if (isInvalid) {
        if(m_behavior == QLandmarkFileHandlerGpx::ExportAll){
            m_errorString = QString("Landmarks cannot be exported with invalid coordinates (latitude is %1, longitude is %2)").arg(latString).arg(lonString);
            m_errorCode = QLandmarkManager::BadArgumentError; //TODO: should be invalid error code?
            return false;
        } else { //m_behavior == QLandmarkFileHandlerGpx::ExportSome
            return true;//ignore landmarks with invalid coordinates.
        }
    }

    m_writer->writeStartElement(m_ns, elementName);

    m_writer->writeAttribute("lat", latString);
    m_writer->writeAttribute("lon", lonString);

    if (!qIsNaN(landmark.coordinate().altitude()))
        m_writer->writeTextElement(m_ns, "ele", QString::number(landmark.coordinate().altitude()));

    if (!landmark.name().isEmpty())
        m_writer->writeTextElement(m_ns, "name", landmark.name());

    if (!landmark.description().isEmpty())
        m_writer->writeTextElement(m_ns, "desc", landmark.description());
    m_writer->writeEndElement();
    return true;
}
    void testProximityFilter()
    {
        QLandmarkProximityFilter proximityFilter;
        proximityFilter.setCenter(QGeoCoordinate(30,30));
        proximityFilter.setRadius( QGeoCoordinate(30,30).distanceTo(QGeoCoordinate(30,32)) );

        //test landmark in the centre
        QLandmark lm;
        lm.setCoordinate(QGeoCoordinate(30,30));
        QVERIFY(MockEngine::testFilter(proximityFilter, lm));

        //test landmark just within the radius
        lm.setCoordinate(QGeoCoordinate(30,28.1));
        QVERIFY(MockEngine::testFilter(proximityFilter, lm));

        //test landmark on the edge the radius
        lm.setCoordinate(QGeoCoordinate(30,28.0));
        QVERIFY(MockEngine::testFilter(proximityFilter, lm));

        //test landmark just outside radius
        lm.setCoordinate(QGeoCoordinate(30,27.9));
        QVERIFY(!MockEngine::testFilter(proximityFilter, lm));

        //test landmark outside radius
        lm.setCoordinate(QGeoCoordinate(30,26));
        QVERIFY(!MockEngine::testFilter(proximityFilter, lm));
    }
    void testUnionFilter()
    {
        QLandmarkCategoryId catId;
        catId.setLocalId("1");
        catId.setManagerUri("qtlandmarks:mock:");

        QLandmarkCategoryId catId2;
        catId2.setLocalId("2");
        catId2.setManagerUri("qtlandmarks:mock:");

        //test a match with the union filter
        QLandmarkUnionFilter unionFilter;
        QLandmarkNameFilter nameFilter("beach");
        QLandmarkProximityFilter proximityFilter(QGeoCoordinate(30,30));
        proximityFilter.setRadius(QGeoCoordinate(30,30).distanceTo(QGeoCoordinate(30,32)));
        QLandmarkCategoryFilter categoryFilter;
        categoryFilter.setCategoryId(catId);

        QLandmark lm;
        lm.setName("statue");
        lm.setCoordinate(QGeoCoordinate(-30,-29));
        lm.addCategoryId(catId);

        unionFilter << nameFilter << categoryFilter << proximityFilter;
        QVERIFY(MockEngine::testFilter(unionFilter,lm));

        //test no match with union filter
        lm.removeCategoryId(catId);
        lm.addCategoryId(catId2);
        QVERIFY(!MockEngine::testFilter(unionFilter,lm));

        //test empty union filter
        unionFilter.clear();
        QVERIFY(!MockEngine::testFilter(unionFilter,lm));
    }
Пример #14
0
void LandmarkBrowser::updateTable(const QList<QLandmark> &lms)
{
    QLandmark lm;
    QTableWidgetItem *item;
    for ( int i =0; i < lms.count(); ++i) {
        lm = lms.at(i);
        table->insertRow(table->rowCount());

        item = new QTableWidgetItem(QString::number(lm.coordinate().latitude(),'f',2));
        item->setFlags(item->flags() & ~Qt::ItemIsEditable);
        table->setItem(table->rowCount()-1,0,item);

        item = new QTableWidgetItem(QString::number(lm.coordinate().longitude(),'f',2));
        item->setFlags(item->flags() & ~Qt::ItemIsEditable);
        table->setItem(table->rowCount()-1,1, item);

        item = new QTableWidgetItem(lm.name());
        item->setFlags(item->flags() & ~Qt::ItemIsEditable);
        table->setItem(table->rowCount()-1,2, item);

        if (i %20)
            qApp->processEvents();
    }
}
Пример #15
0
bool QLandmarkFileHandlerLmx::readMediaLink(QLandmark &landmark)
{
    /*
    <xsd:complexType name="mediaLinkType">
        <xsd:sequence>
            <xsd:element name="name" type="xsd:string" minOccurs="0" />
            <xsd:element name="mime" type="xsd:string" minOccurs="0" />
            <xsd:element name="url" type="xsd:anyURI" />
        </xsd:sequence>
    </xsd:complexType>
    */

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

    if (!m_reader->readNextStartElement()) {
        m_reader->raiseError("The element \"mediaLink\" did not have the required child element \"url\".");
        return false;
    }

    if (m_reader->name() == "name") {
        // Not used outside of schema compliance check
        m_reader->skipCurrentElement();
        if (!m_reader->readNextStartElement()) {
        m_reader->raiseError("The element \"mediaLink\" did not have the required child element \"url\".");
            return false;
        }
    }

    if (m_reader->name() == "mime") {
        // Not used outside of schema compliance check
        m_reader->skipCurrentElement();
        if (!m_reader->readNextStartElement()) {
        m_reader->raiseError("The element \"mediaLink\" did not have the required child element \"url\".");
            return false;
        }
    }

    if (m_reader->name() == "url") {
        landmark.setUrl(m_reader->readElementText());
        if (!m_reader->readNextStartElement())
            return true;
    }

    m_reader->raiseError(QString("The element \"url\" did not expect a child element named \"%1\" at this point (unknown child element or child element out of order).").arg(m_reader->name().toString()));
    return false;
}
Пример #16
0
// Initializes this landmark from the given landmark
void QDeclarativeLandmark::setLandmark(const QLandmark& landmark)
{
    // Elaborate but makes sure appropriate signals are sent
    // (this function is called when landmark updates).
    setPlace(landmark); // viewport, address, coordinate etc.
    setName(landmark.name());
    setPhoneNumber(landmark.phoneNumber());
    setDescription(landmark.description());
    setRadius(landmark.radius());
    setIconSource(landmark.iconUrl());
    setUrl(landmark.url());
    m_landmark = landmark;
}
Пример #17
0
bool QLandmarkFileHandlerGpx::readWaypoint(QLandmark &landmark, const QString &elementName)
{
    /*
    <xsd:complexType name="wptType">
        <xsd:sequence>
            <xsd:element name="ele" type="xsd:decimal" minOccurs="0" />
            <xsd:element name="time" type="xsd:dateTime" minOccurs="0" />
            <xsd:element name="magvar" type="degreesType" minOccurs="0" />
            <xsd:element name="geoidheight" type="xsd:decimal" minOccurs="0" />
            <xsd:element name="name" type="xsd:string" minOccurs="0" />
            <xsd:element name="cmt" type="xsd:string" minOccurs="0" />
            <xsd:element name="desc" type="xsd:string" minOccurs="0" />
            <xsd:element name="src" type="xsd:string" minOccurs="0" />
            <xsd:element name="link" type="linkType" minOccurs="0" maxOccurs="unbounded" />
            <xsd:element name="sym" type="xsd:string" minOccurs="0" />
            <xsd:element name="type" type="xsd:string" minOccurs="0" />
            <xsd:element name="fix" type="fixType" minOccurs="0" />
            <xsd:element name="sat" type="xsd:nonNegativeInteger" minOccurs="0" />
            <xsd:element name="hdop" type="xsd:decimal" minOccurs="0" />
            <xsd:element name="vdop" type="xsd:decimal" minOccurs="0" />
            <xsd:element name="pdop" type="xsd:decimal" minOccurs="0" />
            <xsd:element name="ageofdgpsdata" type="xsd:decimal" minOccurs="0" />
            <xsd:element name="dgpsid" type="dgpsStationType" minOccurs="0" />
            <xsd:element name="extensions" type="extensionsType" minOccurs="0" />
        </xsd:sequence>
        <xsd:attribute name="lat" type="latitudeType" use="required" />
        <xsd:attribute name="lon" type="longitudeType" use="required" />
    </xsd:complexType>

    <xsd:simpleType name="latitudeType">
        <xsd:restriction base="xsd:decimal">
            <xsd:minInclusive value="-90.0"/>
            <xsd:maxInclusive value="90.0"/>
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:simpleType name="longitudeType">
        <xsd:restriction base="xsd:decimal">
            <xsd:minInclusive value="-180.0"/>
            <xsd:maxExclusive value="180.0"/>
        </xsd:restriction>
    </xsd:simpleType>
    */
    Q_ASSERT(m_reader->isStartElement()
             && (m_reader->name() == elementName));

    QGeoCoordinate coord;

    if (m_reader->attributes().hasAttribute("lat")) {
        bool ok = false;
        QString s = m_reader->attributes().value("lat").toString();

        if ((s == "INF") || (s == "-INF") || (s == "NaN")) {
            m_reader->raiseError(QString("The attribute \"lat\" expected a value convertable to type double (value was \"%1\").").arg(s));
            return false;
        }

        double lat = s.toDouble(&ok);

        if (!ok) {
            m_reader->raiseError(QString("The attribute \"lat\" expected a value convertable to type double (value was \"%1\").").arg(s));
            return false;
        }

        if (lat < -90.0 || 90.0 < lat) {
            m_reader->raiseError(QString("The attribute \"lat\" fell outside of the bounds -90.0 <= lat <= 90.0 (value was \"%1\").").arg(s));
            return false;
        }

        coord.setLatitude(lat);
    } else {
        m_reader->raiseError(QString("The element \"%1\" did not have the required attribute \"lat\".").arg(elementName));
        return false;
    }

    if (m_reader->attributes().hasAttribute("lon")) {
        bool ok = false;
        QString s = m_reader->attributes().value("lon").toString();

        if ((s == "INF") || (s == "-INF") || (s == "NaN")) {
            m_reader->raiseError(QString("The attribute \"lon\" expected a value convertable to type double (value was \"%1\").").arg(s));
            return false;
        }

        double lon = s.toDouble(&ok);

        if (!ok) {
            m_reader->raiseError(QString("The attribute \"lon\" expected a value convertable to type double (value was \"%1\").").arg(s));
            return false;
        }

        if (lon < -180.0 || 180.0 <= lon) {
            m_reader->raiseError(QString("The attribute \"lon\" fell outside of the bounds -180.0 <= lat < 180.0 (value was \"%1\").").arg(s));
            return false;
        }

        coord.setLongitude(lon);
    } else {
        m_reader->raiseError(QString("The element \"%1\" did not have the required attribute \"lon\".").arg(elementName));
        return false;
    }

    landmark.setCoordinate(coord);

    if (!m_reader->readNextStartElement())
        return true;

    if (m_reader->name() == "ele") {
        bool ok = false;
        QString s = m_reader->readElementText();

        if ((s == "INF") || (s == "-INF") || (s == "NaN")) {
            m_reader->raiseError(QString("The element \"ele\" expected a value convertable to type double (value was \"%1\").").arg(s));
            return false;
        }

        double alt = s.toDouble(&ok);

        if (!ok) {
            m_reader->raiseError(QString("The element \"ele\" expected a value convertable to type double (value was \"%1\").").arg(s));
            return false;
        }

        coord.setAltitude(alt);
        landmark.setCoordinate(coord);

        if (!m_reader->readNextStartElement())
            return true;
    }

    QList<QString> unusedNames1;
    unusedNames1 << "time";
    unusedNames1 << "magvar";
    unusedNames1 << "geoidheight";

    for (int i = 0; i < unusedNames1.size(); ++i) {
        if (m_reader->name() == unusedNames1.at(i)) {
            // Not used outside of schema compliance check
            m_reader->skipCurrentElement();
            if (!m_reader->readNextStartElement())
                return true;
        }
    }

    if (m_reader->name() == "name") {
        landmark.setName(m_reader->readElementText());
        if (!m_reader->readNextStartElement())
            return true;
    }

    if (m_reader->name() == "cmt") {
        // Not used outside of schema compliance check
        m_reader->skipCurrentElement();
        if (!m_reader->readNextStartElement())
            return true;
    }

    if (m_reader->name() == "desc") {
        landmark.setDescription(m_reader->readElementText());
        if (!m_reader->readNextStartElement())
            return true;
    }

    if (m_reader->name() == "src") {
        // Not used outside of schema compliance check
        m_reader->skipCurrentElement();
        if (!m_reader->readNextStartElement())
            return true;
    }

    while (m_reader->name() == "link") {
        // Not used outside of schema compliance check
        m_reader->skipCurrentElement();
        if (!m_reader->readNextStartElement())
            return true;
    }

    QList<QString> unusedNames2;
    unusedNames2 << "sym";
    unusedNames2 << "type";
    unusedNames2 << "fix";
    unusedNames2 << "sat";
    unusedNames2 << "hdop";
    unusedNames2 << "vdop";
    unusedNames2 << "pdop";
    unusedNames2 << "ageofdgpsdata";
    unusedNames2 << "dgpsid";
    unusedNames2 << "extensions";

    for (int i = 0; i < unusedNames2.size(); ++i) {
        if (m_reader->name() == unusedNames2.at(i)) {
            // Not used outside of schema compliance check
            m_reader->skipCurrentElement();
            if (!m_reader->readNextStartElement())
                return true;
        }
    }

    m_reader->raiseError(QString("The element \"%1\" did not expect a child element named \"%2\" at this point (unknown child element or child element out of order).").arg(elementName).arg(m_reader->name().toString()));
    return false;
}
Пример #18
0
bool QLandmarkFileHandlerLmx::readLandmark(QLandmark &landmark)
{
    /*
    <xsd:complexType name="landmarkType">
        <xsd:sequence>
            <xsd:element name="name" type="xsd:string" minOccurs="0" />
            <xsd:element name="description" type="xsd:string" minOccurs="0" />
            <xsd:element name="coordinates" type="coordinatesType" minOccurs="0" />
            <xsd:element name="coverageRadius" minOccurs="0">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:float">
                        <xsd:minInclusive value="0"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
            <xsd:element name="addressInfo" type="addressInfoType" minOccurs="0" />
            <xsd:element name="mediaLink" type="mediaLinkType" minOccurs="0" maxOccurs="unbounded" />
            <xsd:element name="category" type="categoryType" minOccurs="0" maxOccurs="unbounded" />
        </xsd:sequence>
    </xsd:complexType>
    */

    if(m_cancel && (*m_cancel) == true) {
        m_errorCode = QLandmarkManager::CancelError;
        m_error = "Import of lmx file was canceled";
        return false;
    }

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

    m_landmarkCategoryNames.append(QStringList());

    if (!m_reader->readNextStartElement())
        return true;

    if (m_reader->name() == "name") {
        landmark.setName(m_reader->readElementText());
        if (!m_reader->readNextStartElement())
            return true;
    }

    if (m_reader->name() == "description") {
        landmark.setDescription(m_reader->readElementText());
        if (!m_reader->readNextStartElement())
            return true;
    }

    if (m_reader->name() == "coordinates") {
        if (!readCoordinates(landmark))
            return false;

        if (!m_reader->readNextStartElement())
            return true;
    }

    if (m_reader->name() == "coverageRadius") {
        bool ok = false;
        QString s = m_reader->readElementText();

        if ((s == "INF") || (s == "-INF") || (s == "NaN")) {
            m_reader->raiseError(QString("The element \"coverageRadius\" expected a value convertable to type real (value was \"%1\").").arg(s));
            return false;
        }

        qreal rad = (qreal)(s.toDouble(&ok));

        if (!ok) {
            m_reader->raiseError(QString("The element \"coverageRadius\" expected a value convertable to type real (value was \"%1\").").arg(s));
            return false;
        }

        if (rad < 0.0) {
            m_reader->raiseError(QString("The element \"coverageRadius\" is expected to have a non-negative value (value was \"%1\").").arg(s));
            return false;
        }

        landmark.setRadius(rad);

        if (!m_reader->readNextStartElement())
            return true;
    }

    if (m_reader->name() == "addressInfo") {
        if (!readAddressInfo(landmark))
            return false;

        if (!m_reader->readNextStartElement())
            return true;
    }

    // TODO need to document the fact that only the first link is read
    // and the others are ignored
    bool mediaLinkRead = false;

    while (m_reader->name() == "mediaLink") {
        if (!mediaLinkRead) {
            mediaLinkRead = true;
            if (!readMediaLink(landmark))
                return false;
        }

        if (!m_reader->readNextStartElement())
            return true;
    }


    QStringList categoryNames;
    while (m_reader->name() == "category") {
        QString name;
        if (!readCategory(name))
            return false;
        categoryNames << name;

        if (!m_reader->readNextStartElement()) {
            m_landmarkCategoryNames.last() = categoryNames;
            return true;
        }
    }

    m_reader->raiseError(QString("The element \"landmark\" did not expect a child element named \"%1\" at this point (unknown child element or child element out of order).").arg(m_reader->name().toString()));
    return false;
}
    void testFilterName()
    {
        //test for match - case matches, filter-case insensitive
        QLandmarkNameFilter nameFilter;
        QLandmark lm;
        lm.setName("madara");

        //test case insensitive, start with
        nameFilter.setName("mad");
        nameFilter.setMatchFlags(QLandmarkFilter::MatchStartsWith);
        QVERIFY(MockEngine::testFilter(nameFilter,lm));
        nameFilter.setName("Mad");
        QVERIFY(MockEngine::testFilter(nameFilter,lm));

        //test case sensitive starts with
        nameFilter.setName("mad");
        nameFilter.setMatchFlags(QLandmarkFilter::MatchCaseSensitive | QLandmarkFilter::MatchStartsWith);
        QVERIFY(MockEngine::testFilter(nameFilter,lm));
        nameFilter.setName("Mad");
        QVERIFY(!MockEngine::testFilter(nameFilter,lm));

        //test case insensitive, ends with
        nameFilter.setName("ara");
        nameFilter.setMatchFlags(QLandmarkFilter::MatchEndsWith);
        QVERIFY(MockEngine::testFilter(nameFilter,lm));
        nameFilter.setName("Ara");
        QVERIFY(MockEngine::testFilter(nameFilter,lm));

        //test case sensitive, ends with
        nameFilter.setName("ara");
        nameFilter.setMatchFlags(QLandmarkFilter::MatchCaseSensitive | QLandmarkFilter::MatchEndsWith);
        QVERIFY(MockEngine::testFilter(nameFilter,lm));
        nameFilter.setName("Ara");
        QVERIFY(!MockEngine::testFilter(nameFilter,lm));

        //test case insensitive, contains
        nameFilter.setName("ada");
        nameFilter.setMatchFlags(QLandmarkFilter::MatchContains);
        QVERIFY(MockEngine::testFilter(nameFilter,lm));
        nameFilter.setName("Ada");
        QVERIFY(MockEngine::testFilter(nameFilter,lm));

        //test case sensitive, contains
        nameFilter.setName("ada");
        nameFilter.setMatchFlags(QLandmarkFilter::MatchCaseSensitive | QLandmarkFilter::MatchContains);
        QVERIFY(MockEngine::testFilter(nameFilter,lm));
        nameFilter.setName("Ada");
        QVERIFY(!MockEngine::testFilter(nameFilter,lm));

        //test case insensitive, fixed string
        nameFilter.setName("madara");
        nameFilter.setMatchFlags( QLandmarkFilter::MatchFixedString);
        QVERIFY(MockEngine::testFilter(nameFilter,lm));
        nameFilter.setName("Madara");
        QVERIFY(MockEngine::testFilter(nameFilter,lm));

        //test case sensitive, fixed string
        nameFilter.setName("madara");
        nameFilter.setMatchFlags(QLandmarkFilter::MatchCaseSensitive | QLandmarkFilter::MatchFixedString);
        QVERIFY(MockEngine::testFilter(nameFilter,lm));
        nameFilter.setName("Madara");
        QVERIFY(!MockEngine::testFilter(nameFilter,lm));


        //test case variant match
        nameFilter.setName("madara");
        nameFilter.setMatchFlags(0);
        QVERIFY(MockEngine::testFilter(nameFilter,lm));
        nameFilter.setName("Madara");
        QVERIFY(!MockEngine::testFilter(nameFilter,lm));

        nameFilter.setName("madara");
        nameFilter.setMatchFlags(QLandmarkFilter::MatchCaseSensitive);
        QVERIFY(MockEngine::testFilter(nameFilter,lm));
        nameFilter.setName("Madara");
        QVERIFY(!MockEngine::testFilter(nameFilter,lm));
    }
Пример #20
0
bool QLandmarkFileHandlerLmx::readCoordinates(QLandmark &landmark)
{
    /*
    <xsd:complexType name="coordinatesType">
        <xsd:sequence>
            <xsd:element name="latitude">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:double">
                        <xsd:minInclusive value="-90"/>
                        <xsd:maxInclusive value="90"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
            <xsd:element name="longitude">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:double">
                        <xsd:minInclusive value="-180"/>
                        <xsd:maxExclusive value="180"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
            <xsd:element name="altitude" type="xsd:float" minOccurs="0" />
            <xsd:element name="horizontalAccuracy" minOccurs="0">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:float">
                        <xsd:minInclusive value="0"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
            <xsd:element name="verticalAccuracy" minOccurs="0">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:float">
                        <xsd:minInclusive value="0"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
            <xsd:element name="timeStamp" type="xsd:dateTime" minOccurs="0" />
        </xsd:sequence>
    </xsd:complexType>
    */

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

    if (!m_reader->readNextStartElement()) {
        m_reader->raiseError("The element \"coordinates\" did not have the required child element \"latitude\".");
        return false;
    }

    if (m_reader->name() == "latitude") {
        bool ok = false;
        QString s = m_reader->readElementText();

        if ((s == "INF") || (s == "-INF") || (s == "NaN")) {
            m_reader->raiseError(QString("The element \"latitude\" expected a value convertable to type double (value was \"%1\").").arg(s));
            return false;
        }

        double lat = s.toDouble(&ok);

        if (!ok) {
            m_reader->raiseError(QString("The element \"latitude\" expected a value convertable to type double (value was \"%1\").").arg(s));
            return false;
        }

        if (lat < -90.0 || 90.0 < lat) {
            m_reader->raiseError(QString("The element \"latitude\" fell outside of the bounds -90.0 <= latitude <= 90.0 (value was \"%1\").").arg(s));
            return false;
        }

        QGeoCoordinate coord = landmark.coordinate();
        coord.setLatitude(lat);
        landmark.setCoordinate(coord);

        if (!m_reader->readNextStartElement()) {
            m_reader->raiseError("The element \"coordinates\" did not have the required child element \"longitude\".");
            return false;
        }
    } else {
        m_reader->raiseError("The element \"coordinates\" did not have the required child element \"latitude\".");
        return false;
    }

    if (m_reader->name() == "longitude") {
        bool ok = false;
        QString s = m_reader->readElementText();

        if ((s == "INF") || (s == "-INF") || (s == "NaN")) {
            m_reader->raiseError(QString("The element \"longitude\" expected a value convertable to type double (value was \"%1\").").arg(s));
            return false;
        }

        double lon = s.toDouble(&ok);

        if (!ok) {
            m_reader->raiseError(QString("The element \"longitude\" expected a value convertable to type double (value was \"%1\").").arg(s));
            return false;
        }

        if (lon < -180.0 || 180.0 <= lon) {
            m_reader->raiseError(QString("The element \"longitude\" fell outside of the bounds -180.0 <= longitude < 180.0 (value was \"%1\").").arg(s));
            return false;
        }

        QGeoCoordinate coord = landmark.coordinate();
        coord.setLongitude(lon);
        landmark.setCoordinate(coord);

        if (!m_reader->readNextStartElement())
            return true;
    } else {
        m_reader->raiseError("The element \"coordinates\" did not have the required child element \"longitude\".");
        return false;
    }

    if (m_reader->name() == "altitude") {
        bool ok = false;
        QString s = m_reader->readElementText();

        if ((s == "INF") || (s == "-INF") || (s == "NaN")) {
            m_reader->raiseError(QString("The element \"altitude\" expected a value convertable to type double (value was \"%1\").").arg(s));
            return false;
        }

        double alt = s.toDouble(&ok);

        if (!ok) {
            m_reader->raiseError(QString("The element \"altitude\" expected a value convertable to type float (value was \"%1\").").arg(s));
            return false;
        }

        QGeoCoordinate coord = landmark.coordinate();
        coord.setAltitude(alt);
        landmark.setCoordinate(coord);

        if (!m_reader->readNextStartElement())
            return true;
    }

    QList<QString> names;
    names << "horizontalAccuracy";
    names << "verticalAccuracy";
    names << "timeStamp";

    for (int i = 0; i < names.size(); ++i) {
        // Not used outside of schema compliance check
        if (m_reader->name() == names.at(i)) {
           m_reader->skipCurrentElement();
           if (!m_reader->readNextStartElement())
               return true;
        }
    }

    m_reader->raiseError(QString("The element \"coordinate\" did not expect a child element named \"%1\" at this point (unknown child element or child element out of order).").arg(m_reader->name().toString()));
    return false;
}
Пример #21
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;
}
    void testFilterCategory() {
        //test category matches
        QLandmarkCategoryFilter categoryFilter;
        QLandmarkCategoryId catFilterId;
        catFilterId.setLocalId("1");
        catFilterId.setManagerUri("qtlandmarks:mock:");
        categoryFilter.setCategoryId(catFilterId);

        QLandmark lm;
        QLandmarkCategoryId lmCatId;
        lmCatId.setLocalId("1");
        lmCatId.setManagerUri("qtlandmarks:mock:");
        lm.addCategoryId(lmCatId);

        QVERIFY(MockEngine::testFilter(categoryFilter,lm));

        //test category id doesn't match
        lm.removeCategoryId(lmCatId);
        QVERIFY(lm.categoryIds().count() == 0);
        lmCatId.setLocalId("2");
        lm.addCategoryId(lmCatId);

        QVERIFY(!MockEngine::testFilter(categoryFilter,lm));

        //test category uri that doesn't match
        QList<QLandmarkCategoryId> catIdList;
        lm.setCategoryIds(catIdList);
        QVERIFY(lm.categoryIds().count() == 0);
        lmCatId.setLocalId("1");
        lmCatId.setManagerUri("qtlandmarks:fake:");
        catIdList.append(lmCatId);
        lm.setCategoryIds(catIdList);
        QVERIFY(lm.categoryIds().count() == 1);
        QVERIFY(!MockEngine::testFilter(categoryFilter,lm));


        //try match a category when the
        //landmark has multiple categories

        QLandmarkCategoryId lmCatId2;
        QLandmarkCategoryId lmCatId3;

        lmCatId.setLocalId("1");
        lmCatId.setManagerUri("qtlandmarks:mock:");

        lmCatId2.setLocalId("2");
        lmCatId2.setManagerUri("qtlandmarks:mock:");

        lmCatId3.setLocalId("3");
        lmCatId3.setManagerUri("qtlandmarks:mock:");

        catIdList.clear();
        catIdList << lmCatId << lmCatId2 << lmCatId3;
        lm.setCategoryIds(catIdList);

        catFilterId.setLocalId("2");
        catFilterId.setManagerUri("qtlandmarks:mock:");

        categoryFilter.setCategoryId(catFilterId);
        QVERIFY(MockEngine::testFilter(categoryFilter, lm));

        //category id doesn't match when the landmark
        //has multipl catgories
        catFilterId.setLocalId("4");
        categoryFilter.setCategoryId(catFilterId);
    }
Пример #23
0
LandmarkAddDialog::LandmarkAddDialog(QWidget *parent, Qt::WindowFlags flags, const QLandmark &landmark)
    : QDialog(parent, flags)
{
    setupUi(this);
    if (landmark != QLandmark()) {
        setWindowTitle("Edit Landmark");

        lm = landmark;
        nameLineEdit->setText(landmark.name());
        latitudeLineEdit->setText(QString::number(landmark.coordinate().latitude()));
        longitudeLineEdit->setText(QString::number(landmark.coordinate().longitude()));
        streetLineEdit->setText(landmark.address().street());
        districtLineEdit->setText(landmark.address().district());
        cityLineEdit->setText(landmark.address().city());
        countyLineEdit->setText(landmark.address().county());
        stateLineEdit->setText(landmark.address().state());
        countryLineEdit->setText(landmark.address().country());
        descriptionLineEdit->setText(landmark.description());
        iconUrlLineEdit->setText(landmark.iconUrl().toString());
        urlLineEdit->setText(landmark.url().toString());
        phoneLineEdit->setText(landmark.phoneNumber());
        radiusLineEdit->setText(QString::number(landmark.radius()));
    } else {
        setWindowTitle("Add Landmark");
    }

    QLandmarkManager manager;
    QList<QLandmarkCategory> categories = manager.categories();

    foreach( QLandmarkCategory category, categories) {
        QListWidgetItem  *categoryItem = new QListWidgetItem(categoryList,QListWidgetItem::UserType + 1);
        categoryItem->setData(Qt::DisplayRole,category.name());
        QVariant var;
        var.setValue(category.categoryId());
        categoryItem->setData(Qt::UserRole, var);
        categoryItem->setFlags(Qt::ItemIsEnabled);
        if (landmark.categoryIds().contains(category.categoryId()))
            categoryItem->setCheckState(Qt::Checked);
        else
            categoryItem->setCheckState(Qt::Unchecked);
    }