Пример #1
0
void LocalDatabaseRunner::search( const QString &searchTerm, const GeoDataLatLonAltBox &preferred )
{
    QVector<GeoDataPlacemark*> vector;

    if (model()) {
        const QAbstractItemModel * placemarkModel = model()->placemarkModel();

        if (placemarkModel) {
            QModelIndexList resultList;
            QModelIndex firstIndex = placemarkModel->index( 0, 0 );
            resultList = placemarkModel->match( firstIndex,
                                    Qt::DisplayRole, searchTerm, -1,
                                    Qt::MatchStartsWith );

            foreach ( const QModelIndex& index, resultList )
            {
                if( !index.isValid() ) {
                    mDebug() << "invalid index!!!";
                    continue;
                }
                GeoDataPlacemark *placemark = dynamic_cast<GeoDataPlacemark*>(qvariant_cast<GeoDataObject*>( index.data( MarblePlacemarkModel::ObjectPointerRole )));
                if ( placemark &&
                     ( preferred.isEmpty() || preferred.contains( placemark->coordinate() ) ) ) {
                    vector.append( new GeoDataPlacemark( *placemark ));
                }
            }
        }
    }

    emit searchFinished( vector );
}
Пример #2
0
void OsmNominatimRunner::search( const QString &searchTerm, const GeoDataLatLonAltBox &preferred )
{    
    QString base = "http://nominatim.openstreetmap.org/search?";
    QString query = "q=%1&format=xml&addressdetails=1&accept-language=%2";
    QString url = QString(base + query).arg(searchTerm).arg(MarbleLocale::languageCode());
    if( !preferred.isEmpty() ) {
        GeoDataCoordinates::Unit deg = GeoDataCoordinates::Degree;
        QString viewbox( "&viewbox=%1,%2,%3,%4&bounded=1" ); // left, top, right, bottom
        url += viewbox.arg(preferred.west(deg))
                      .arg(preferred.north(deg))
                      .arg(preferred.east(deg))
                      .arg(preferred.south(deg));

    }
    m_request.setUrl(QUrl(url));
    m_request.setRawHeader("User-Agent", TinyWebBrowser::userAgent("Browser", "OsmNominatimRunner") );

    QEventLoop eventLoop;

    QTimer timer;
    timer.setSingleShot( true );
    timer.setInterval( 15000 );

    connect( &timer, SIGNAL(timeout()),
             &eventLoop, SLOT(quit()));
    connect( this, SIGNAL(searchFinished(QVector<GeoDataPlacemark*>)),
             &eventLoop, SLOT(quit()) );

    // @todo FIXME Must currently be done in the main thread, see bug 257376
    QTimer::singleShot( 0, this, SLOT(startSearch()) );
    timer.start();

    eventLoop.exec();
}
Пример #3
0
GeoDataLatLonAltBox GeoDataContainer::latLonAltBox() const
{
    Q_D(const GeoDataContainer);
    GeoDataLatLonAltBox result;

    QVector<GeoDataFeature*>::const_iterator it = d->m_vector.constBegin();
    QVector<GeoDataFeature*>::const_iterator end = d->m_vector.constEnd();
    for (; it != end; ++it) {

        // Get all the placemarks from GeoDataContainer
        if ( (*it)->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
            GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>(*it);

            // Only use visible placemarks for extracting their latLonAltBox and
            // making an union with the global latLonAltBox Marble will fit its
            // zoom to
            if (placemark->isVisible())
            {
                if (result.isEmpty()) {
                    result = placemark->geometry()->latLonAltBox();
                } else {
                    result |= placemark->geometry()->latLonAltBox();
                }
            }
        }
        else if ( (*it)->nodeType() == GeoDataTypes::GeoDataFolderType
                 || (*it)->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
            GeoDataContainer *container = static_cast<GeoDataContainer*>(*it);
            if (result.isEmpty()) {
                result = container->latLonAltBox();
            } else {
                result |= container->latLonAltBox();
            }
        }
    }
    return result;
}
Пример #4
0
GeoDataLatLonAltBox GeoDataMultiGeometry::latLonAltBox() const
{
    QVector<GeoDataGeometry*>::const_iterator it = p()->m_vector.constBegin();
    QVector<GeoDataGeometry*>::const_iterator end = p()->m_vector.constEnd();

    GeoDataLatLonAltBox box;
    for (; it != end; ++it) {
        if ( !(*it)->latLonAltBox().isEmpty() ) {
            if ( box.isEmpty() ) {
                box = (*it)->latLonAltBox();
            }
            else {
                box |= (*it)->latLonAltBox();
            }
        }
    }
    return box;
}
Пример #5
0
void TestGeoDataLatLonAltBox::testDefaultConstruction()
{
    GeoDataLatLonBox const latLonBox;

    QCOMPARE( latLonBox.north(), 0.0 );
    QCOMPARE( latLonBox.south(), 0.0 );
    QCOMPARE( latLonBox.east(), 0.0 );
    QCOMPARE( latLonBox.west(), 0.0 );
    QCOMPARE( latLonBox.rotation(), 0.0 );
    QCOMPARE( latLonBox.width(), 0.0 );
    QCOMPARE( latLonBox.height(), 0.0 );
    QVERIFY( !latLonBox.crossesDateLine() );
    QCOMPARE( latLonBox.center(), GeoDataCoordinates( 0, 0 ) );
    QVERIFY( latLonBox.isNull() );
    QVERIFY( latLonBox.isEmpty() );

    QVERIFY( (latLonBox|latLonBox).isNull() );
    QVERIFY( (latLonBox|latLonBox).isEmpty() );
    QVERIFY( !latLonBox.intersects( latLonBox ) );


    GeoDataLatLonAltBox const latLonAltBox;

    QCOMPARE( latLonAltBox.north(), 0.0 );
    QCOMPARE( latLonAltBox.south(), 0.0 );
    QCOMPARE( latLonAltBox.east(), 0.0 );
    QCOMPARE( latLonAltBox.west(), 0.0 );
    QCOMPARE( latLonAltBox.rotation(), 0.0 );
    QCOMPARE( latLonAltBox.width(), 0.0 );
    QCOMPARE( latLonAltBox.height(), 0.0 );
    QVERIFY( !latLonAltBox.crossesDateLine() );
    QCOMPARE( latLonAltBox.center(), GeoDataCoordinates( 0, 0, 0 ) );
    QVERIFY( latLonAltBox.isNull() );
    QVERIFY( latLonAltBox.isEmpty() );
    QCOMPARE( latLonAltBox.minAltitude(), 0.0 );
    QCOMPARE( latLonAltBox.maxAltitude(), 0.0 );
    QCOMPARE( latLonAltBox.altitudeMode(), ClampToGround );

    QVERIFY( (latLonAltBox|latLonAltBox).isNull() );
    QVERIFY( (latLonAltBox|latLonAltBox).isEmpty() );
    QVERIFY( !latLonAltBox.intersects( latLonAltBox ) );
}