Example #1
0
void tst_QGeoCircle::assignment()
{
    QGeoCircle c1 = QGeoCircle(QGeoCoordinate(10.0, 0.0), 20.0);
    QGeoCircle c2 = QGeoCircle(QGeoCoordinate(20.0, 0.0), 30.0);

    QVERIFY(c1 != c2);

    c2 = c1;
    QCOMPARE(c2.center(), QGeoCoordinate(10.0, 0.0));
    QCOMPARE(c2.radius(), 20.0);
    QCOMPARE(c1, c2);

    c2.setCenter(QGeoCoordinate(30.0, 0.0));
    c2.setRadius(15.0);
    QCOMPARE(c1.center(), QGeoCoordinate(10.0, 0.0));
    QCOMPARE(c1.radius(), 20.0);

    // Assign c1 to an area
    QGeoShape area = c1;
    QCOMPARE(area.type(), c1.type());
    QVERIFY(area == c1);

    // Assign the area back to a bounding circle
    QGeoCircle ca = area;
    QCOMPARE(ca.center(), c1.center());
    QCOMPARE(ca.radius(), c1.radius());

    // Check that the copy is not modified when modifying the original.
    c1.setCenter(QGeoCoordinate(15.0, 15.0));
    QVERIFY(ca.center() != c1.center());
    QVERIFY(ca != c1);
}
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;
    }
}
/*!
    \internal
*/
QVariant QDeclarativeSearchModelBase::searchArea() const
{
    QGeoShape s = m_request.searchArea();
    if (s.type() == QGeoShape::RectangleType)
        return QVariant::fromValue(QGeoRectangle(s));
    else if (s.type() == QGeoShape::CircleType)
        return QVariant::fromValue(QGeoCircle(s));
    else
        return QVariant::fromValue(s);
}
void GeoCircleValueType::setValue(const QVariant &value)
{
    if (value.userType() == qMetaTypeId<QGeoCircle>())
        v = value.value<QGeoCircle>();
    else if (value.userType() == qMetaTypeId<QGeoShape>())
        v = value.value<QGeoShape>();
    else
        v = QGeoCircle();

    onLoad();
}
Example #5
0
void tst_QGeoCircle::boxComparison_data()
{
    QTest::addColumn<QGeoRectangle>("box");
    QTest::addColumn<QGeoCircle>("circle");
    QTest::addColumn<bool>("equal");

    QGeoCircle c(QGeoCoordinate(10.0, 0.0), 10.0);
    QGeoRectangle b(QGeoCoordinate(10.0, 0.0), QGeoCoordinate(0.0, 10.0));

    QTest::newRow("default constructed") << QGeoRectangle() << QGeoCircle() << false;
    QTest::newRow("b c") << b << c << false;
}
void GeoCircleValueType::writeVariantValue(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags, QVariant *from)
{
    if (from->userType() == qMetaTypeId<QGeoCircle>()) {
        writeProperty(obj, idx, flags, from);
    } else if (from->userType() == qMetaTypeId<QGeoShape>()) {
        QGeoCircle c = from->value<QGeoShape>();
        QVariant v = QVariant::fromValue(c);
        writeProperty(obj, idx, flags, &v);
    } else {
        QVariant v = QVariant::fromValue(QGeoCircle());
        writeProperty(obj, idx, flags, &v);
    }
}
Example #7
0
void tst_QGeoCircle::areaComparison_data()
{
    QTest::addColumn<QGeoShape>("area");
    QTest::addColumn<QGeoCircle>("circle");
    QTest::addColumn<bool>("equal");

    QGeoCircle c1(QGeoCoordinate(10.0, 0.0), 10.0);
    QGeoCircle c2(QGeoCoordinate(20.0, 10.0), 20.0);
    QGeoRectangle b(QGeoCoordinate(10.0, 0.0), QGeoCoordinate(0.0, 10.0));

    QTest::newRow("default constructed") << QGeoShape() << QGeoCircle() << false;
    QTest::newRow("c1 c1") << QGeoShape(c1) << c1 << true;
    QTest::newRow("c1 c2") << QGeoShape(c1) << c2 << false;
    QTest::newRow("c2 c1") << QGeoShape(c2) << c1 << false;
    QTest::newRow("c2 c2") << QGeoShape(c2) << c2 << true;
    QTest::newRow("b c1") << QGeoShape(b) << c1 << false;
}
/*
    This property holds the coordinate of the center of the geocircle.
*/
QGeoCoordinate GeoCircleValueType::center()
{
    return QGeoCircle(v).center();
}
QVariant GeoCircleValueType::value()
{
    return QVariant::fromValue(QGeoCircle(v));
}
/*!
    This property holds the radius of the geocircle in meters.

    The default value for the radius is -1 indicating an invalid geocircle area.
*/
qreal GeoCircleValueType::radius() const
{
    return QGeoCircle(v).radius();
}
Example #11
0
/*!
    \qmlmethod geocircle QtPositioning::circle(coordinate center, real radius) const

    Constructs a geocircle centered at \a center with a radius of \a radius meters.
*/
QGeoCircle LocationSingleton::circle(const QGeoCoordinate &center, qreal radius) const
{
    return QGeoCircle(center, radius);
}
Example #12
0
/*!
    \qmlmethod geocircle QtPositioning::circle() const

    Constructs an invalid geocircle.

    \sa {geocircle}
*/
QGeoCircle LocationSingleton::circle() const
{
    return QGeoCircle();
}