File indexing completed on 2024-12-08 03:36:21

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2011 Dennis Nienhüser <nienhueser@kde.org>
0004 // SPDX-FileCopyrightText: 2013 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
0005 //
0006 
0007 #include "LocalOsmSearchRunner.h"
0008 #include "DatabaseQuery.h"
0009 
0010 #include "MarbleDebug.h"
0011 #include "GeoDataPoint.h"
0012 
0013 #include <QString>
0014 #include <QVector>
0015 #include <QUrl>
0016 
0017 namespace Marble
0018 {
0019 
0020 QMap<OsmPlacemark::OsmCategory, GeoDataPlacemark::GeoDataVisualCategory> LocalOsmSearchRunner::m_categoryMap;
0021 
0022 LocalOsmSearchRunner::LocalOsmSearchRunner( const QStringList &databaseFiles, QObject *parent ) :
0023     SearchRunner( parent ),
0024     m_database( databaseFiles )
0025 {
0026     if ( m_categoryMap.isEmpty() ) {
0027         m_categoryMap[OsmPlacemark::UnknownCategory] = GeoDataPlacemark::OsmSite;
0028         m_categoryMap[OsmPlacemark::Address] = GeoDataPlacemark::OsmSite;
0029         m_categoryMap[OsmPlacemark::AccomodationCamping] = GeoDataPlacemark::AccomodationCamping;
0030         m_categoryMap[OsmPlacemark::AccomodationHostel] = GeoDataPlacemark::AccomodationHostel;
0031         m_categoryMap[OsmPlacemark::AccomodationHotel] = GeoDataPlacemark::AccomodationHotel;
0032         m_categoryMap[OsmPlacemark::AccomodationMotel] = GeoDataPlacemark::AccomodationMotel;
0033         m_categoryMap[OsmPlacemark::AccomodationYouthHostel] = GeoDataPlacemark::AccomodationYouthHostel;
0034         m_categoryMap[OsmPlacemark::AmenityLibrary] = GeoDataPlacemark::AmenityLibrary;
0035         m_categoryMap[OsmPlacemark::EducationCollege] = GeoDataPlacemark::EducationCollege;
0036         m_categoryMap[OsmPlacemark::EducationSchool] = GeoDataPlacemark::EducationSchool;
0037         m_categoryMap[OsmPlacemark::EducationUniversity] = GeoDataPlacemark::EducationUniversity;
0038         m_categoryMap[OsmPlacemark::FoodBar] = GeoDataPlacemark::FoodBar;
0039         m_categoryMap[OsmPlacemark::FoodBiergarten] = GeoDataPlacemark::FoodBiergarten;
0040         m_categoryMap[OsmPlacemark::FoodCafe] = GeoDataPlacemark::FoodCafe;
0041         m_categoryMap[OsmPlacemark::FoodFastFood] = GeoDataPlacemark::FoodFastFood;
0042         m_categoryMap[OsmPlacemark::FoodPub] = GeoDataPlacemark::FoodPub;
0043         m_categoryMap[OsmPlacemark::FoodRestaurant] = GeoDataPlacemark::FoodRestaurant;
0044         m_categoryMap[OsmPlacemark::HealthDoctors] = GeoDataPlacemark::HealthDoctors;
0045         m_categoryMap[OsmPlacemark::HealthHospital] = GeoDataPlacemark::HealthHospital;
0046         m_categoryMap[OsmPlacemark::HealthPharmacy] = GeoDataPlacemark::HealthPharmacy;
0047         m_categoryMap[OsmPlacemark::MoneyAtm] = GeoDataPlacemark::MoneyAtm;
0048         m_categoryMap[OsmPlacemark::MoneyBank] = GeoDataPlacemark::MoneyBank;
0049         m_categoryMap[OsmPlacemark::ShoppingBeverages] = GeoDataPlacemark::ShopBeverages;
0050         m_categoryMap[OsmPlacemark::ShoppingHifi] = GeoDataPlacemark::ShopHifi;
0051         m_categoryMap[OsmPlacemark::ShoppingSupermarket] = GeoDataPlacemark::ShopSupermarket;
0052         m_categoryMap[OsmPlacemark::TouristAttraction] = GeoDataPlacemark::TourismAttraction;
0053         m_categoryMap[OsmPlacemark::TouristCastle] = GeoDataPlacemark::HistoricCastle;
0054         m_categoryMap[OsmPlacemark::TouristCinema] = GeoDataPlacemark::AmenityCinema;
0055         m_categoryMap[OsmPlacemark::TouristMonument] = GeoDataPlacemark::HistoricMonument;
0056         m_categoryMap[OsmPlacemark::TouristMuseum] = GeoDataPlacemark::TourismMuseum;
0057         m_categoryMap[OsmPlacemark::TouristRuin] = GeoDataPlacemark::HistoricRuins;
0058         m_categoryMap[OsmPlacemark::TouristTheatre] = GeoDataPlacemark::AmenityTheatre;
0059         m_categoryMap[OsmPlacemark::TouristThemePark] = GeoDataPlacemark::TourismThemePark;
0060         m_categoryMap[OsmPlacemark::TouristViewPoint] = GeoDataPlacemark::TourismViewPoint;
0061         m_categoryMap[OsmPlacemark::TouristZoo] = GeoDataPlacemark::TourismZoo;
0062         m_categoryMap[OsmPlacemark::HistoricMemorial] = GeoDataPlacemark::HistoricMemorial;
0063         m_categoryMap[OsmPlacemark::TransportAirport] = GeoDataPlacemark::TransportAerodrome;
0064         m_categoryMap[OsmPlacemark::TransportAirportTerminal] = GeoDataPlacemark::TransportAirportTerminal;
0065         m_categoryMap[OsmPlacemark::TransportAirportRunway] = GeoDataPlacemark::TransportAirportRunway;
0066         m_categoryMap[OsmPlacemark::TransportAirportApron] = GeoDataPlacemark::TransportAirportApron;
0067         m_categoryMap[OsmPlacemark::TransportAirportTaxiway] = GeoDataPlacemark::TransportAirportTaxiway;
0068         m_categoryMap[OsmPlacemark::TransportBusStation] = GeoDataPlacemark::TransportBusStation;
0069         m_categoryMap[OsmPlacemark::TransportBusStop] = GeoDataPlacemark::TransportBusStop;
0070         m_categoryMap[OsmPlacemark::TransportCarShare] = GeoDataPlacemark::TransportCarShare;
0071         m_categoryMap[OsmPlacemark::TransportFuel] = GeoDataPlacemark::TransportFuel;
0072         m_categoryMap[OsmPlacemark::TransportParking] = GeoDataPlacemark::TransportParking;
0073         m_categoryMap[OsmPlacemark::TransportTrainStation] = GeoDataPlacemark::TransportTrainStation;
0074         m_categoryMap[OsmPlacemark::TransportTramStop] = GeoDataPlacemark::TransportTramStop;
0075         m_categoryMap[OsmPlacemark::TransportRentalBicycle] = GeoDataPlacemark::TransportRentalBicycle;
0076         m_categoryMap[OsmPlacemark::TransportRentalCar] = GeoDataPlacemark::TransportRentalCar;
0077         m_categoryMap[OsmPlacemark::TransportSpeedCamera] = GeoDataPlacemark::TransportSpeedCamera;
0078         m_categoryMap[OsmPlacemark::TransportTaxiRank] = GeoDataPlacemark::TransportTaxiRank;
0079         m_categoryMap[OsmPlacemark::PlacesRegion] = GeoDataPlacemark::OsmSite;
0080         m_categoryMap[OsmPlacemark::PlacesCounty] = GeoDataPlacemark::OsmSite;
0081         m_categoryMap[OsmPlacemark::PlacesCity] = GeoDataPlacemark::PlaceCity;
0082         m_categoryMap[OsmPlacemark::PlacesTown] = GeoDataPlacemark::PlaceTown;
0083         m_categoryMap[OsmPlacemark::PlacesVillage] = GeoDataPlacemark::PlaceVillage;
0084         m_categoryMap[OsmPlacemark::PlacesHamlet] = GeoDataPlacemark::PlaceHamlet;
0085         m_categoryMap[OsmPlacemark::PlacesIsolatedDwelling] = GeoDataPlacemark::OsmSite;
0086         m_categoryMap[OsmPlacemark::PlacesSuburb] = GeoDataPlacemark::PlaceSuburb;
0087         m_categoryMap[OsmPlacemark::PlacesLocality] = GeoDataPlacemark::PlaceLocality;
0088         m_categoryMap[OsmPlacemark::PlacesIsland] = GeoDataPlacemark::OsmSite;
0089     }
0090 }
0091 
0092 LocalOsmSearchRunner::~LocalOsmSearchRunner()
0093 {
0094 }
0095 
0096 
0097 void LocalOsmSearchRunner::search( const QString &searchTerm, const GeoDataLatLonBox &preferred )
0098 {
0099     const DatabaseQuery userQuery( model(), searchTerm, preferred );
0100 
0101     QVector<OsmPlacemark> placemarks = m_database.find( userQuery );
0102 
0103     QVector<GeoDataPlacemark*> result;
0104     for( const OsmPlacemark &placemark: placemarks ) {
0105         GeoDataPlacemark* hit = new GeoDataPlacemark;
0106         hit->setName( placemark.name() );
0107         if ( placemark.category() == OsmPlacemark::Address && !placemark.houseNumber().isEmpty() ) {
0108             hit->setName(hit->name() + QLatin1Char(' ') + placemark.houseNumber());
0109         }
0110         if ( !placemark.additionalInformation().isEmpty() ) {
0111             hit->setName(hit->name() + QLatin1Char('(') + placemark.additionalInformation() + QLatin1Char(')'));
0112         }
0113         if ( placemark.category() != OsmPlacemark::UnknownCategory ) {
0114             hit->setVisualCategory( m_categoryMap[placemark.category()] );
0115         }
0116         hit->setGeometry( new GeoDataPoint( placemark.longitude(), placemark.latitude(), 0.0, GeoDataCoordinates::Degree ) );
0117         result << hit;
0118     }
0119 
0120     emit searchFinished( result );
0121 }
0122 
0123 } // namespace Marble
0124 
0125 #include "moc_LocalOsmSearchRunner.cpp"