void tst_QGeoAddress::copy_constructor()
{
    QGeoAddress *qgeoaddresscopy = new QGeoAddress();
    QVERIFY(qgeoaddresscopy->isEmpty());
    QCOMPARE(*qgeoaddress, *qgeoaddresscopy);
    delete qgeoaddresscopy;
}
Example #2
0
void tst_QGeoLocation::isEmpty()
{
    QGeoAddress address;
    address.setCity(QStringLiteral("Braunschweig"));
    QVERIFY(!address.isEmpty());

    QGeoRectangle boundingBox;
    boundingBox.setTopLeft(QGeoCoordinate(1, -1));
    boundingBox.setBottomRight(QGeoCoordinate(-1, 1));
    QVERIFY(!boundingBox.isEmpty());

    QGeoLocation location;

    QVERIFY(location.isEmpty());

    // address
    location.setAddress(address);
    QVERIFY(!location.isEmpty());
    location.setAddress(QGeoAddress());
    QVERIFY(location.isEmpty());

    // coordinate
    location.setCoordinate(QGeoCoordinate(1, 2));
    QVERIFY(!location.isEmpty());
    location.setCoordinate(QGeoCoordinate());
    QVERIFY(location.isEmpty());

    // bounding box
    location.setBoundingBox(boundingBox);
    QVERIFY(!location.isEmpty());
    location.setBoundingBox(QGeoRectangle());
    QVERIFY(location.isEmpty());
}
Example #3
0
void GeoHelper::searchFinishedSlot(QGeoSearchReply *reply)
{
    if (reply->error() == QGeoSearchReply::NoError)
    {
        QScriptEngine scriptEngine;
        QScriptValue replyObject = scriptEngine.newArray();

        QList<QGeoPlace> places = reply->places();
        for (int i = 0; i < places.count(); i++)
        {
            QScriptValue placeObject = scriptEngine.newObject();

            QScriptValue coordinateObject = scriptEngine.newObject();
            QGeoCoordinate coordinate = places[i].coordinate();
            coordinateObject.setProperty("latitude", QScriptValue(coordinate.latitude()));
            coordinateObject.setProperty("longitude", QScriptValue(coordinate.longitude()));
            placeObject.setProperty("coordinate", coordinateObject);

            QScriptValue addressObject = scriptEngine.newObject();
            QGeoAddress address = places[i].address();

            if (!address.isEmpty())
            {
                addressObject.setProperty("country", address.country());
                addressObject.setProperty("countryCode", address.countryCode());
                addressObject.setProperty("state", address.state());
                addressObject.setProperty("county", address.county());
                addressObject.setProperty("city", address.city());
                addressObject.setProperty("district", address.district());
                addressObject.setProperty("street", address.street());
                addressObject.setProperty("postcode", address.postcode());

            }

            placeObject.setProperty("address", addressObject);
            replyObject.setProperty(i, placeObject);
        }


        QScriptValue fun = scriptEngine.evaluate("(function(a) { return JSON.stringify(a); })");
        QScriptValueList args;
        args << replyObject;
        QScriptValue result = fun.call(QScriptValue(), args);

        emit searchReply(result.toString());
    }


}
void tst_QGeoAddress::emptyClearTest()
{
    QGeoAddress testObj;
    QVERIFY(testObj.isEmpty());

    testObj.setCountry(QLatin1String("country"));
    QVERIFY(!testObj.isEmpty());
    testObj.clear();

    testObj.setCountryCode(QLatin1String("countryCode"));
    QVERIFY(!testObj.isEmpty());
    testObj.clear();

    testObj.setState(QLatin1String("state"));
    QVERIFY(!testObj.isEmpty());
    testObj.clear();

    testObj.setCounty(QLatin1String("county"));
    QVERIFY(!testObj.isEmpty());
    testObj.clear();

    testObj.setCity(QLatin1String("city"));
    QVERIFY(!testObj.isEmpty());
    testObj.clear();

    testObj.setDistrict(QLatin1String("district"));
    QVERIFY(!testObj.isEmpty());
    testObj.clear();

    testObj.setPostalCode(QLatin1String("postalCode"));
    QVERIFY(!testObj.isEmpty());
    testObj.clear();

    testObj.setStreet(QLatin1String("street"));
    QVERIFY(!testObj.isEmpty());
    testObj.clear();

    testObj.setText(QLatin1String("formatted address"));
    QVERIFY(!testObj.isEmpty());
    testObj.clear();

    QVERIFY(testObj.isEmpty());
}