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));
    }
/*!
    Returns whether the bounding box \a boundingBox is contained within this
    bounding box.
*/
bool QGeoBoundingBox::contains(const QGeoBoundingBox &boundingBox) const
{
    return (contains(boundingBox.topLeft())
            && contains(boundingBox.topRight())
            && contains(boundingBox.bottomLeft())
            && contains(boundingBox.bottomRight()));
}
Example #3
0
//-------------------------------------------------------------------------------------------------
void GeoPresenter::showBoundingBox(QTreeWidgetItem* routeItem, const QGeoBoundingBox& box)
{
    QTreeWidgetItem* boxItem = new QTreeWidgetItem(routeItem);
    boxItem->setText(0, "bounding box");

    QTreeWidgetItem* nwItem = new QTreeWidgetItem(boxItem);
    nwItem->setText(0, "NW");
    nwItem->setText(1, formatGeoCoordinate(box.topLeft()));

    QTreeWidgetItem* seItem = new QTreeWidgetItem(boxItem);
    seItem->setText(0, "SE");
    seItem->setText(1, formatGeoCoordinate(box.bottomRight()));
}
Example #4
0
/*!
    Returns a bounding box which contains this map object.

    If this map object has children, the bounding box will be large
    enough to contain both this map object and all of its children.
    \since 1.1
*/
QGeoBoundingBox QGeoMapGroupObject::boundingBox() const
{
    QGeoBoundingBox bounds;

    if (d_ptr->children.size() == 0)
        return bounds;

    bounds = d_ptr->children.at(0)->boundingBox();

    for (int i = 1; i < d_ptr->children.size(); ++i)
        bounds = bounds.united(d_ptr->children.at(i)->boundingBox());

    return bounds;
}
QDeclarativeGeoBoundingBox::QDeclarativeGeoBoundingBox(const QGeoBoundingBox& box, QObject* parent) :
    QObject(parent),
    m_declarativeBottomLeft(box.bottomLeft()),
    m_declarativeBottomRight(box.bottomRight()),
    m_declarativeTopLeft(box.topLeft()),
    m_declarativeTopRight(box.topRight()),
    m_declarativeCenter(box.center()),
    m_box(box),
    m_height(box.height()),
    m_width(box.width())
{
}
QGeoSearchReply* QGeoSearchManagerEngineCm::search(const QString &searchString,
        QGeoSearchManager::SearchTypes searchTypes,
        int limit,
        int offset,
        QGeoBoundingArea *bounds)
{
	// Prepare request url for Geocoding:
	QString requestString = "http://" + m_host + "/" + m_token +"/geocoding/v2/find.js?query=" + searchString;


	if (limit > 0) {
		// Number of results to return 
		requestString += "&results=" + QString::number(limit);
	}
	if (offset > 0) {
		// Number of results to skip from beginning (allow paging of results)
		requestString += "&skip=" + QString::number(offset);
	}

	if ((bounds) && (bounds->isValid())) {
        QGeoBoundingBox* box = 0;
        QGeoBoundingCircle* circle = 0;
        switch (bounds->type()) {

			// Note:  Searching with Bounding area specified could be extremely slow for large areas
			//		  so use it only with high zoom level in frontend map application
            case QGeoBoundingArea::BoxType:
                box = static_cast<QGeoBoundingBox*>(bounds);
                if (box && box->isValid()) {
					DBG_CM(SEARCH_M, INFO_L, "Using search with bounding box specified");
					// "southern_latitude,western_longitude,northern_latitude,eastern_longitude"
					requestString += "&bbox=";
					requestString += QString::number(box->bottomLeft().latitude()) + "," ;	// southern_latitude
					requestString += QString::number(box->bottomLeft().longitude()) + "," ;	// western_longitude
					requestString += QString::number(box->topRight().latitude()) + "," ;	// northern_latitude
					requestString += QString::number(box->topRight().longitude());			// eastern_longitude
					requestString += "&bbox_only=false";
                }
                break;
            case QGeoBoundingArea::CircleType:
                circle = static_cast<QGeoBoundingCircle*>(bounds);
                if (circle && circle->isValid()) {
					DBG_CM(SEARCH_M, ERR_L, "Using search with circle area specified: Not implemented. Around area is ignored!");
                }
                break;
            default:
                break;
        }

	}

	// return location information like road, city, county, country, postcode in returned results:
    // requestString += "&return_location=true";

	return search(requestString, bounds, limit, offset);
}
bool LandmarkFilterDialog::setupFetchRequest()
{
    if (filterAllCheckBox->checkState() == Qt::Checked) {
        fetchRequest->setFilter(QLandmarkFilter());
        fetchRequest->setSorting(QLandmarkNameSort());
    } else {
        QLandmarkIntersectionFilter filter;
        QLandmarkSortOrder sortOrder = QLandmarkNameSort();

        if (filterNameCheckBox->checkState() == Qt::Checked) {
            QLandmarkNameFilter nameFilter;
            nameFilter.setName(nameLineEdit->text());
            if (startsWithRadioButton->isChecked())
                nameFilter.setMatchFlags(QLandmarkFilter::MatchStartsWith);
            else
                nameFilter.setMatchFlags(QLandmarkFilter::MatchContains);
            filter.append(nameFilter);
        }

        if (filterCategoryCheckBox->checkState() == Qt::Checked) {
            QLandmarkCategoryFilter categoryFilter;
            if (categoryComboBox->count() > 0) {
                oldCategoryId = categoryComboBox->itemData(categoryComboBox->currentIndex())
                            .value<QLandmarkCategoryId>();
                categoryFilter.setCategoryId(oldCategoryId);
            }
            filter.append(categoryFilter);
        }

        if (filterBoxCheckBox->checkState() == Qt::Checked) {

            if (!isValidLatitude(boxTopLeftLatitudeLineEdit->text())) {
                QMessageBox::warning(this,"Warning", "Top left latitude is invalid.  Must be between -90 and 90 (not inclusive)", QMessageBox::Ok, QMessageBox::NoButton);
                return false;
            }
            else if (!isValidLongitude(boxTopLeftLongitudeLineEdit->text())) {
                QMessageBox::warning(this,"Warning", "Top left longitude is invalid. Must be between -180 and 180 (inclusive) ", QMessageBox::Ok, QMessageBox::NoButton);
                return false;
            }
            else if (!isValidLatitude(boxBottomRightLatitudeLineEdit->text())) {
                QMessageBox::warning(this,"Warning", "Bottom right latitude is invalid. (Must be between -90 and 90 (not inclusive)", QMessageBox::Ok, QMessageBox::NoButton);
                return false;
            }
            else if (!isValidLongitude(boxBottomRightLongitudeLineEdit->text())) {
                QMessageBox::warning(this,"Warning", "Bottom right longitude is invalid. (Must be between -180 and 180 (inclusive)", QMessageBox::Ok, QMessageBox::NoButton);
                return false;
            }

            QGeoCoordinate topLeft;
            topLeft.setLatitude(boxTopLeftLatitudeLineEdit->text().toDouble());
            topLeft.setLongitude(boxTopLeftLongitudeLineEdit->text().toDouble());
            QGeoCoordinate bottomRight;
            bottomRight.setLatitude(boxBottomRightLatitudeLineEdit->text().toDouble());
            bottomRight.setLongitude(boxBottomRightLongitudeLineEdit->text().toDouble());

            QGeoBoundingBox box;
            box.setTopLeft(topLeft);
            box.setBottomRight(bottomRight);
            QLandmarkBoxFilter boxFilter;
            boxFilter.setBoundingBox(box);
            filter.append(boxFilter);
        }

        if (filterProximityCheckBox->checkState() == Qt::Checked) {
            if (!isValidLatitude(proximityLatitudeLineEdit->text())) {
                QMessageBox::warning(this,"Warning", "Proximity latitude is invalid.  It must be between -90 and 90 (not inclusive)", QMessageBox::Ok, QMessageBox::NoButton);
                return false;
            } else if (!isValidLongitude(proximityLongitudeLineEdit->text())) {
                QMessageBox::warning(this,"Warning", "Proximity longitude is invalid. It must be between -180 and 180 (inclusive) ", QMessageBox::Ok, QMessageBox::NoButton);
                return false;
            }
            bool ok;
            qreal radius = radiusLineEdit->text().toDouble(&ok);
            if (!ok) {
                QMessageBox::warning(this,"Warning", "Proximity radius is invalid. It must be a number", QMessageBox::Ok, QMessageBox::NoButton);
                return false;
            }

            QLandmarkProximityFilter proximityFilter;
            QGeoCoordinate center;
            center.setLatitude(proximityLatitudeLineEdit->text().toDouble());
            center.setLongitude(proximityLongitudeLineEdit->text().toDouble());
            proximityFilter.setCenter(center);
            proximityFilter.setRadius(radiusLineEdit->text().toDouble());
            filter.append(proximityFilter);
            sortOrder = QLandmarkSortOrder();
        }

        fetchRequest->setFilter(filter);
        fetchRequest->setSorting(sortOrder);
    }
    return true;
}
QString QGeoRoutingManagerEngineNokia::routeRequestString(const QGeoRouteRequest &request) const
{
    QString requestString;

    int numAreas = request.excludeAreas().count();
    if (numAreas > 0) {
        requestString += "&avoidareas";
        for (int i = 0;i < numAreas;++i) {
            requestString += i == 0 ? "=" : ";";
            QGeoBoundingBox box = request.excludeAreas().at(i);
            requestString += trimDouble(box.topLeft().latitude());
            requestString += ",";
            requestString += trimDouble(box.topLeft().longitude());
            requestString += ",";
            requestString += trimDouble(box.bottomRight().latitude());
            requestString += ",";
            requestString += trimDouble(box.bottomRight().longitude());
        }
    }

//    TODO: work out what was going on here
//    - segment and instruction/maneuever functions are mixed and matched
//    - tried to implement sensible equivalents below
//    QStringList legAttributes;
//    if (request.instructionDetail() & QGeoRouteRequest::BasicSegmentData) {
//        requestString += "&linkattributes=sh,le"; //shape,length
//        legAttributes.append("links");
//    }
//
//    if (request.instructionDetail() & QGeoRouteRequest::BasicInstructions) {
//        legAttributes.append("maneuvers");
//        requestString += "&maneuverattributes=po,tt,le,di"; //position,traveltime,length,direction
//        if (!(request.instructionDetail() & QGeoRouteRequest::NoSegmentData))
//            requestString += ",li"; //link
//    }

    QStringList legAttributes;
    if (request.segmentDetail() & QGeoRouteRequest::BasicSegmentData) {
        requestString += "&linkattributes=sh,le"; //shape,length
        legAttributes.append("links");
    }

    if (request.maneuverDetail() & QGeoRouteRequest::BasicManeuvers) {
        legAttributes.append("maneuvers");
        requestString += "&maneuverattributes=po,tt,le,di"; //position,traveltime,length,direction
        if (!(request.segmentDetail() & QGeoRouteRequest::NoSegmentData))
            requestString += ",li"; //link
    }

    requestString += "&routeattributes=sm,sh,bb,lg"; //summary,shape,boundingBox,legs
    if (legAttributes.count() > 0) {
        requestString += "&legattributes=";
        requestString += legAttributes.join(",");
    }

    requestString += "&departure=";
    requestString += QDateTime::currentDateTime().toUTC().toString("yyyy-MM-ddThh:mm:ssZ");

    requestString += "&instructionformat=text";

    requestString += "&language=";
    requestString += locale().name();

    return requestString;
}