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 ); }
void PlasmaRunner::collectMatches(QList<Plasma::QueryMatch> &matches, const QString &query, const GeoDataFolder *folder) { const QString queryLower = query.toLower(); QVector<GeoDataFeature*>::const_iterator it = folder->constBegin(); QVector<GeoDataFeature*>::const_iterator end = folder->constEnd(); for (; it != end; ++it) { GeoDataFolder *folder = dynamic_cast<GeoDataFolder*>(*it); if ( folder ) { collectMatches(matches, query, folder); continue; } GeoDataPlacemark *placemark = dynamic_cast<GeoDataPlacemark*>( *it ); if ( placemark ) { // For short query strings only match exactly, to get a sane number of matches if (query.length() < minContainsMatchLength) { if ( placemark->name().toLower() != queryLower && ( placemark->descriptionIsCDATA() || // TODO: support also with CDATA placemark->description().toLower() != queryLower ) ) { continue; } } else { if ( ! placemark->name().toLower().contains(queryLower) && ( placemark->descriptionIsCDATA() || // TODO: support also with CDATA ! placemark->description().toLower().contains(queryLower) ) ) { continue; } } const GeoDataCoordinates coordinates = placemark->coordinate(); const qreal lon = coordinates.longitude(GeoDataCoordinates::Degree); const qreal lat = coordinates.latitude(GeoDataCoordinates::Degree); const QVariant coordinatesData = QVariantList() << QVariant(lon) << QVariant(lat) << QVariant(placemark->lookAt()->range()*METER2KM); Plasma::QueryMatch match(this); match.setIcon(QIcon::fromTheme(QStringLiteral("marble"))); match.setText(placemark->name()); match.setSubtext(i18n("Show in OpenStreetMap with Marble")); match.setData(coordinatesData); match.setId(placemark->name()+QString::number(lat)+QString::number(lon)); match.setRelevance(1.0); match.setType(Plasma::QueryMatch::ExactMatch); matches << match; } } }
const GeoDataLatLonAltBox& GeoDataRegion::latLonAltBox() const { // FIXME: This isn't exactly what a 'const' function should do, is it? // If the latLonAltBox hasn't been set try to determine it automatically if ( !d->m_latLonAltBox ) { // If there is a parent try to if ( d->m_parent ) { if ( d->m_parent->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) { GeoDataPlacemark * placemark = dynamic_cast<GeoDataPlacemark*>( d->m_parent ); GeoDataGeometry * geometry = placemark->geometry(); if ( geometry ) { // TODO: automatically calculate the geometry from the // GeoDataGeometry object. // return geometry->latLonAltBox(); } d->m_latLonAltBox = new GeoDataLatLonAltBox( placemark->coordinate() ); } else { // If the parent is not a placemark then create a default LatLonAltBox // FIXME: reference a shared object instead d->m_latLonAltBox = new GeoDataLatLonAltBox(); } } else { // If there is no parent then create a default LatLonAltBox // FIXME: reference a shared object instead d->m_latLonAltBox = new GeoDataLatLonAltBox(); } } return *(d->m_latLonAltBox); }