diff --git a/Tests/src/HeaderCheck.cpp b/Tests/src/HeaderCheck.cpp index 03e3ee1d4..e2c9af045 100644 --- a/Tests/src/HeaderCheck.cpp +++ b/Tests/src/HeaderCheck.cpp @@ -141,7 +141,9 @@ static const std::set allowedDependencies{ "osmscoutclient => osmscout", "osmscoutclient => osmscout.async", "osmscoutclient => osmscout.db", + "osmscoutclient => osmscout.feature", "osmscoutclient => osmscout.io", + "osmscoutclient => osmscout.poi", "osmscoutclient => osmscout.routing", "osmscoutclient => osmscout.util", "osmscoutclient => osmscout.location", @@ -157,7 +159,6 @@ static const std::set allowedDependencies{ "osmscoutclientqt => osmscout.feature", "osmscoutclientqt => osmscout.elevation", "osmscoutclientqt => osmscout.location", - "osmscoutclientqt => osmscout.poi", "osmscoutclientqt => osmscout.routing", "osmscoutclientqt => osmscout.navigation", "osmscoutclientqt => osmscout", diff --git a/libosmscout-client-qt/CMakeLists.txt b/libosmscout-client-qt/CMakeLists.txt index eb07ab24c..20e090813 100644 --- a/libosmscout-client-qt/CMakeLists.txt +++ b/libosmscout-client-qt/CMakeLists.txt @@ -2,7 +2,6 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(HEADER_FILES - include/osmscoutclientqt/AdminRegionInfo.h include/osmscoutclientqt/ClientQtImportExport.h include/osmscoutclientqt/ElevationChartWidget.h include/osmscoutclientqt/ElevationModule.h @@ -52,7 +51,6 @@ set(HEADER_FILES include/osmscoutclientqt/QtStdConverters.h include/osmscoutclientqt/RouteStep.h include/osmscoutclientqt/NearPOIModel.h - include/osmscoutclientqt/POILookupModule.h include/osmscoutclientqt/InstalledMapsModel.h include/osmscoutclientqt/Voice.h include/osmscoutclientqt/VoiceManager.h @@ -108,7 +106,6 @@ set(SOURCE_FILES src/osmscoutclientqt/QtSettingsStorage.cpp src/osmscoutclientqt/QtStdConverters.cpp src/osmscoutclientqt/NearPOIModel.cpp - src/osmscoutclientqt/POILookupModule.cpp src/osmscoutclientqt/InstalledMapsModel.cpp src/osmscoutclientqt/Voice.cpp src/osmscoutclientqt/VoiceManager.cpp diff --git a/libosmscout-client-qt/include/meson.build b/libosmscout-client-qt/include/meson.build index 79d943d07..dd0072fa6 100644 --- a/libosmscout-client-qt/include/meson.build +++ b/libosmscout-client-qt/include/meson.build @@ -1,7 +1,6 @@ osmscoutclientqtIncDir = include_directories('.') osmscoutclientqtHeader = [ - 'osmscoutclientqt/AdminRegionInfo.h', 'osmscoutclientqt/ClientQtImportExport.h', 'osmscoutclientqt/ElevationChartWidget.h', 'osmscoutclientqt/ElevationModule.h', @@ -50,7 +49,6 @@ osmscoutclientqtHeader = [ 'osmscoutclientqt/TiledMapOverlay.h', 'osmscoutclientqt/TiledRenderingHelper.h', 'osmscoutclientqt/NearPOIModel.h', - 'osmscoutclientqt/POILookupModule.h', 'osmscoutclientqt/InstalledMapsModel.h', 'osmscoutclientqt/Voice.h', 'osmscoutclientqt/VoiceManager.h', diff --git a/libosmscout-client-qt/include/osmscoutclientqt/LocationEntry.h b/libosmscout-client-qt/include/osmscoutclientqt/LocationEntry.h index 78098d171..7e77076b6 100644 --- a/libosmscout-client-qt/include/osmscoutclientqt/LocationEntry.h +++ b/libosmscout-client-qt/include/osmscoutclientqt/LocationEntry.h @@ -30,8 +30,10 @@ #include #include +#include +#include + #include -#include namespace osmscout { @@ -51,15 +53,8 @@ class OSMSCOUT_CLIENT_QT_API LocationEntry : public QObject Q_PROPERTY(double lat READ getLat CONSTANT) Q_PROPERTY(double lon READ getLon CONSTANT) -public: - enum Type { - typeNone, - typeObject, - typeCoordinate - }; - private: - Type type; + LocationInfo::Type type; QString label; QString altName; // name in alternative language QString objectType; @@ -70,7 +65,7 @@ class OSMSCOUT_CLIENT_QT_API LocationEntry : public QObject osmscout::GeoBox bbox; public: - LocationEntry(Type type, + LocationEntry(LocationInfo::Type type, const QString& label, const QString& altName, const QString& objectType, @@ -84,6 +79,8 @@ class OSMSCOUT_CLIENT_QT_API LocationEntry : public QObject const osmscout::GeoCoord& coord, QObject* parent = nullptr); + explicit LocationEntry(const LocationInfo &info); + explicit LocationEntry(QObject* parent = nullptr); //! copy constructor copies Qt ownership @@ -104,7 +101,7 @@ class OSMSCOUT_CLIENT_QT_API LocationEntry : public QObject Q_INVOKABLE double distanceTo(double lat, double lon) const; - Type getType() const; + LocationInfo::Type getType() const; QString getTypeString() const; QString getObjectType() const; QString getLabel() const; diff --git a/libosmscout-client-qt/include/osmscoutclientqt/NearPOIModel.h b/libosmscout-client-qt/include/osmscoutclientqt/NearPOIModel.h index 44a205a2c..8adcb0c42 100644 --- a/libosmscout-client-qt/include/osmscoutclientqt/NearPOIModel.h +++ b/libosmscout-client-qt/include/osmscoutclientqt/NearPOIModel.h @@ -20,14 +20,18 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include + #include -#include #include #include #include +#include +#include + namespace osmscout { #define INVALID_COORD -1000.0 @@ -95,29 +99,37 @@ Q_OBJECT void SearchingChanged(bool); - void lookupPOIRequest(int requestId, - osmscout::BreakerRef breaker, - osmscout::GeoCoord searchCenter, - QStringList types, - double maxDistance); + void lookupFinished(int requestId); + void lookupResult(int requestId, QList locations); public slots: void onLookupFinished(int requestId); void onLookupResult(int requestId, QList locations); private: - bool searching{false}; int currentRequest{0}; QList locations; osmscout::GeoCoord searchCenter{INVALID_COORD,INVALID_COORD}; int resultLimit{100}; - osmscout::BreakerRef breaker; + std::optional future; Distance maxDistance{Distance::Of(1)}; QStringList types; POILookupModule *poiModule{nullptr}; SettingsRef settings; + Slot lookupFinishedSlot{ std::bind(&NearPOIModel::lookupFinished, this, std::placeholders::_1) }; + + Slot lookupResultSlot { + [this](int requestId, const POILookupModule::LookupResult &locationsVector) { + QList locations; + for (const auto &info: locationsVector) { + locations << LocationEntry(info); + } + emit lookupResult(requestId, locations); + } + }; + public: NearPOIModel(); ~NearPOIModel() override; @@ -134,7 +146,7 @@ public slots: inline bool isSearching() const { - return searching; + return future.has_value(); } inline double GetLat() const diff --git a/libosmscout-client-qt/include/osmscoutclientqt/OSMScoutQt.h b/libosmscout-client-qt/include/osmscoutclientqt/OSMScoutQt.h index 6bc9f246a..55eeb00fc 100644 --- a/libosmscout-client-qt/include/osmscoutclientqt/OSMScoutQt.h +++ b/libosmscout-client-qt/include/osmscoutclientqt/OSMScoutQt.h @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -34,7 +35,6 @@ #include #include #include -#include #include #include #include diff --git a/libosmscout-client-qt/include/osmscoutclientqt/POILookupModule.h b/libosmscout-client-qt/include/osmscoutclientqt/POILookupModule.h deleted file mode 100644 index 8749a5726..000000000 --- a/libosmscout-client-qt/include/osmscoutclientqt/POILookupModule.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef OSMSCOUT_CLIENT_QT_POILOOKUPSERVICE_H -#define OSMSCOUT_CLIENT_QT_POILOOKUPSERVICE_H -/* - OSMScout - a Qt backend for libosmscout and libosmscout-map - Copyright (C) 2018 Lukas Karas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include - -#include - -#include - -#include - -namespace osmscout { - -/** - * \ingroup QtAPI - */ -class OSMSCOUT_CLIENT_QT_API POILookupModule: public QObject -{ - Q_OBJECT - -signals: - void lookupAborted(int requestId); - void lookupFinished(int requestId); - void lookupResult(int requestId, QList locations); - -public slots: - void lookupPOIRequest(int requestId, - osmscout::BreakerRef breaker, - osmscout::GeoCoord searchCenter, - QStringList types, - double maxDistance); - -private: - QThread *thread; - DBThreadRef dbThread; - -public: - POILookupModule(QThread *thread,DBThreadRef dbThread); - - ~POILookupModule() override; - -private: - QList doPOIlookup(DBInstanceRef db, - osmscout::GeoBox searchBoundingBox, - osmscout::BreakerRef breaker, - QStringList types); - -}; - -} - -#endif //OSMSCOUT_CLIENT_QT_POILOOKUPSERVICE_H diff --git a/libosmscout-client-qt/include/osmscoutclientqt/QtStdConverters.h b/libosmscout-client-qt/include/osmscoutclientqt/QtStdConverters.h index 6ef418c9e..08ff534f4 100644 --- a/libosmscout-client-qt/include/osmscoutclientqt/QtStdConverters.h +++ b/libosmscout-client-qt/include/osmscoutclientqt/QtStdConverters.h @@ -42,6 +42,16 @@ extern OSMSCOUT_CLIENT_QT_API QDateTime TimestampToQDateTime(const osmscout::Tim extern OSMSCOUT_CLIENT_QT_API QList PathVectorToQDirList(const std::vector &paths); +template +QList vectorToQList(const std::vector &vec) +{ + QList result; + for (const auto &o: vec) { + result << o; + } + return result; +} + } #endif //OSMSCOUT_CLIENT_QT_QTSTDCONVERTERS_H diff --git a/libosmscout-client-qt/include/osmscoutclientqt/StyleModule.h b/libosmscout-client-qt/include/osmscoutclientqt/StyleModule.h index 10c900249..aae660fee 100644 --- a/libosmscout-client-qt/include/osmscoutclientqt/StyleModule.h +++ b/libosmscout-client-qt/include/osmscoutclientqt/StyleModule.h @@ -23,6 +23,7 @@ #include #include #include +#include #include diff --git a/libosmscout-client-qt/src/meson.build b/libosmscout-client-qt/src/meson.build index 9a98667d2..52d18ca57 100644 --- a/libosmscout-client-qt/src/meson.build +++ b/libosmscout-client-qt/src/meson.build @@ -46,7 +46,6 @@ osmscoutclientqtSrc = [ 'src/osmscoutclientqt/TiledMapOverlay.cpp', 'src/osmscoutclientqt/TiledRenderingHelper.cpp', 'src/osmscoutclientqt/NearPOIModel.cpp', - 'src/osmscoutclientqt/POILookupModule.cpp', 'src/osmscoutclientqt/InstalledMapsModel.cpp', 'src/osmscoutclientqt/Voice.cpp', 'src/osmscoutclientqt/VoiceManager.cpp', diff --git a/libosmscout-client-qt/src/osmscoutclientqt/LocationEntry.cpp b/libosmscout-client-qt/src/osmscoutclientqt/LocationEntry.cpp index 993280894..14862ba38 100644 --- a/libosmscout-client-qt/src/osmscoutclientqt/LocationEntry.cpp +++ b/libosmscout-client-qt/src/osmscoutclientqt/LocationEntry.cpp @@ -19,13 +19,15 @@ */ #include +#include + #include #include namespace osmscout { -LocationEntry::LocationEntry(Type type, +LocationEntry::LocationEntry(LocationInfo::Type type, const QString& label, const QString& altName, const QString& objectType, @@ -51,7 +53,7 @@ LocationEntry::LocationEntry(const QString& label, const osmscout::GeoCoord& coord, QObject* parent) : QObject(parent), - type(typeCoordinate), + type(LocationInfo::Type::typeCoordinate), label(label), coord(coord) { @@ -60,11 +62,27 @@ LocationEntry::LocationEntry(const QString& label, LocationEntry::LocationEntry(QObject* parent) : QObject(parent), - type(typeNone) + type(LocationInfo::Type::typeNone) { // no code } +LocationEntry::LocationEntry(const LocationInfo &info): + LocationEntry(info.type, + QString::fromStdString(info.label), + QString::fromStdString(info.altName), + QString::fromStdString(info.objectType), + vectorToQList<>(info.adminRegionList), + QString::fromStdString(info.database), + info.coord, + info.bbox, + nullptr) +{ + for (const auto &ref: info.references) { + addReference(ref); + } +} + LocationEntry::LocationEntry(const LocationEntry& other) : QObject(other.parent()), // make copy of Qt ownership type(other.type), @@ -126,14 +144,14 @@ LocationEntry& LocationEntry::operator=(LocationEntry&& other) { void LocationEntry::addReference(const osmscout::ObjectFileRef reference) { - assert(type==typeObject); + assert(type==LocationInfo::Type::typeObject); references.push_back(reference); } void LocationEntry::mergeWith(const LocationEntry &location) { - assert(type==typeObject); - assert(location.type==typeObject); + assert(type==LocationInfo::Type::typeObject); + assert(location.type==LocationInfo::Type::typeObject); bbox.Include(location.bbox); for (auto &ref:location.getReferences()) { @@ -150,7 +168,7 @@ Q_INVOKABLE double LocationEntry::distanceTo(double lat, double lon) const return osmscout::GetSphericalDistance(coord, osmscout::GeoCoord(lat, lon)).AsMeter(); } -LocationEntry::Type LocationEntry::getType() const +LocationInfo::Type LocationEntry::getType() const { return type; } @@ -158,9 +176,9 @@ LocationEntry::Type LocationEntry::getType() const QString LocationEntry::getTypeString() const { switch (type){ - case typeObject: + case LocationInfo::Type::typeObject: return "object"; - case typeCoordinate: + case LocationInfo::Type::typeCoordinate: return "coordinate"; default: return "none"; diff --git a/libosmscout-client-qt/src/osmscoutclientqt/LocationInfoModel.cpp b/libosmscout-client-qt/src/osmscoutclientqt/LocationInfoModel.cpp index 232ff0f73..72de9c1db 100644 --- a/libosmscout-client-qt/src/osmscoutclientqt/LocationInfoModel.cpp +++ b/libosmscout-client-qt/src/osmscoutclientqt/LocationInfoModel.cpp @@ -333,21 +333,21 @@ void LocationInfoModel::onLocationAdminRegions(const osmscout::GeoCoord location const AdminRegionInfoRef bottom=regions.first(); QStringList regionNames=LookupModule::AdminRegionNames(regions, settings->GetShowAltLanguage()); - obj[LabelRole] = bottom->qStringName(); + obj[LabelRole] = QString::fromStdString(bottom->name()); obj[RegionRole] = regionNames; - obj[AddressRole] = bottom->qStringName(); + obj[AddressRole] = QString::fromStdString(bottom->name()); obj[InPlaceRole] = true; obj[DistanceRole] = 0; obj[BearingRole] = ""; obj[PoiRole] = ""; - obj[TypeRole] = bottom->type; + obj[TypeRole] = QString::fromStdString(bottom->type); obj[PostalCodeRole] = ""; obj[WebsiteRole] = ""; obj[PhoneRole] = ""; obj[AddressLocationRole] = ""; obj[AddressNumberRole] = ""; obj[IndexedAdminRegionRole] = QStringList(); - obj[AltLangName] = bottom->qStringAltName(); + obj[AltLangName] = QString::fromStdString(bottom->altName()); obj[OpeningHours] = ""; model << obj; diff --git a/libosmscout-client-qt/src/osmscoutclientqt/LookupModule.cpp b/libosmscout-client-qt/src/osmscoutclientqt/LookupModule.cpp index cdf93ef7a..b2549163d 100644 --- a/libosmscout-client-qt/src/osmscoutclientqt/LookupModule.cpp +++ b/libosmscout-client-qt/src/osmscoutclientqt/LookupModule.cpp @@ -341,7 +341,7 @@ AdminRegionInfoRef LookupModule::buildAdminRegionInfo(const DBInstanceRef &db, return info; } - info->database=QString::fromStdString(db->path); + info->database=db->path; // read admin region features auto database=db->GetDatabase(); @@ -359,19 +359,19 @@ AdminRegionInfoRef LookupModule::buildAdminRegionInfo(const DBInstanceRef &db, case osmscout::refNode: if (database->GetNodeByOffset(region->object.GetFileOffset(), node)) { adminLevelValue=adminLevelReader.GetValue(node->GetFeatureValueBuffer()); - info->type=QString::fromStdString(node->GetType()->GetName()); + info->type=node->GetType()->GetName(); } break; case osmscout::refWay: if (database->GetWayByOffset(region->object.GetFileOffset(), way)) { adminLevelValue=adminLevelReader.GetValue(way->GetFeatureValueBuffer()); - info->type=QString::fromStdString(way->GetType()->GetName()); + info->type=way->GetType()->GetName(); } break; case osmscout::refArea: if (database->GetAreaByOffset(region->object.GetFileOffset(), area)) { adminLevelValue=adminLevelReader.GetValue(area->GetFeatureValueBuffer()); - info->type=QString::fromStdString(area->GetType()->GetName()); + info->type=area->GetType()->GetName(); } break; case osmscout::refNone: @@ -497,7 +497,7 @@ QStringList LookupModule::AdminRegionNames(const QList ®i QString previousName; QString name; for (const auto ®ion: regionList) { - name = (useAltNames && !region->altName().empty()) ? region->qStringAltName() : region->qStringName(); + name = QString::fromStdString( (useAltNames && !region->altName().empty()) ? region->altName() : region->name()); if (previousName != name) { result << name; previousName = name; @@ -515,7 +515,7 @@ QStringList LookupModule::IndexedAdminRegionNames(const QListadminLevel >= 0 && region->adminLevel < result.size()) { - result[region->adminLevel] = (useAltNames && !region->altName().empty()) ? region->qStringAltName() : region->qStringName(); + result[region->adminLevel] = QString::fromStdString((useAltNames && !region->altName().empty()) ? region->altName() : region->name()); } } return result; diff --git a/libosmscout-client-qt/src/osmscoutclientqt/NearPOIModel.cpp b/libosmscout-client-qt/src/osmscoutclientqt/NearPOIModel.cpp index 4cdafbf69..354ed90ad 100644 --- a/libosmscout-client-qt/src/osmscoutclientqt/NearPOIModel.cpp +++ b/libosmscout-client-qt/src/osmscoutclientqt/NearPOIModel.cpp @@ -19,6 +19,7 @@ #include #include +#include namespace osmscout { @@ -27,31 +28,28 @@ NearPOIModel::NearPOIModel() poiModule=OSMScoutQt::GetInstance().MakePOILookupModule(); settings=OSMScoutQt::GetInstance().GetSettings(); - connect(this, &NearPOIModel::lookupPOIRequest, - poiModule, &POILookupModule::lookupPOIRequest, - Qt::QueuedConnection); - - connect(poiModule, &POILookupModule::lookupAborted, + connect(this, &NearPOIModel::lookupFinished, this, &NearPOIModel::onLookupFinished, Qt::QueuedConnection); - connect(poiModule, &POILookupModule::lookupFinished, - this, &NearPOIModel::onLookupFinished, - Qt::QueuedConnection); - connect(poiModule, &POILookupModule::lookupResult, + connect(this, &NearPOIModel::lookupResult, this, &NearPOIModel::onLookupResult, Qt::QueuedConnection); + + poiModule->lookupResult.Connect(lookupResultSlot); + poiModule->lookupAborted.Connect(lookupFinishedSlot); + poiModule->lookupAborted.Connect(lookupFinishedSlot); } NearPOIModel::~NearPOIModel() { locations.clear(); - if (breaker){ - breaker->Break(); - breaker.reset(); + if (future){ + future->Cancel(); + future.reset(); } if (poiModule!=nullptr){ - poiModule->deleteLater(); + poiModule->DeleteLater(); poiModule=nullptr; } } @@ -70,7 +68,7 @@ QVariant NearPOIModel::data(const QModelIndex &index, int role) const case LabelRole: return location->getLabel(); case TypeRole: - if (location->getType()==LocationEntry::typeCoordinate) + if (location->getType()==LocationInfo::Type::typeCoordinate) return "coordinate"; else return location->getObjectType(); @@ -152,8 +150,8 @@ void NearPOIModel::onLookupFinished(int requestId) if (requestId!=currentRequest){ return; } - searching=false; - emit SearchingChanged(searching); + future.reset(); + emit SearchingChanged(future.has_value()); } void NearPOIModel::onLookupResult(int requestId, QList newLocations) @@ -188,8 +186,9 @@ void NearPOIModel::onLookupResult(int requestId, QList newLocatio void NearPOIModel::lookupPOI() { - if (breaker){ - breaker->Break(); + if (future){ + future->Cancel(); + future.reset(); } if (!locations.isEmpty()){ @@ -205,14 +204,10 @@ void NearPOIModel::lookupPOI() maxDistance.AsMeter()>0 && resultLimit>0){ - breaker=std::make_shared(); - searching=true; // TODO: use resultLimit - emit lookupPOIRequest(++currentRequest, breaker, searchCenter, types, maxDistance.AsMeter()); - }else{ - searching=false; + future = poiModule->lookupPOIRequest(++currentRequest, searchCenter, QStringListToStringVector(types), maxDistance); } - emit SearchingChanged(searching); + emit SearchingChanged(future.has_value()); } } diff --git a/libosmscout-client-qt/src/osmscoutclientqt/OSMScoutQt.cpp b/libosmscout-client-qt/src/osmscoutclientqt/OSMScoutQt.cpp index dc45f749a..6544524ec 100644 --- a/libosmscout-client-qt/src/osmscoutclientqt/OSMScoutQt.cpp +++ b/libosmscout-client-qt/src/osmscoutclientqt/OSMScoutQt.cpp @@ -415,11 +415,7 @@ StyleModule* OSMScoutQt::MakeStyleModule() POILookupModule *OSMScoutQt::MakePOILookupModule() { - QThread *thread=makeThread("POILookupModule"); - POILookupModule *module=new POILookupModule(thread,dbThread); - module->moveToThread(thread); - thread->start(); - return module; + return new POILookupModule(dbThread); } ElevationModule *OSMScoutQt::MakeElevationModule() diff --git a/libosmscout-client-qt/src/osmscoutclientqt/OverlayObject.cpp b/libosmscout-client-qt/src/osmscoutclientqt/OverlayObject.cpp index 5d7866201..2454ad66d 100644 --- a/libosmscout-client-qt/src/osmscoutclientqt/OverlayObject.cpp +++ b/libosmscout-client-qt/src/osmscoutclientqt/OverlayObject.cpp @@ -113,7 +113,7 @@ LocationEntry* OverlayObject::getBBoxAsLocation() const GeoBox bbox = boundingBox(); // QML will take ownership - return new LocationEntry(LocationEntry::Type::typeNone, + return new LocationEntry(LocationInfo::Type::typeNone, "bbox", "bbox", "", diff --git a/libosmscout-client-qt/src/osmscoutclientqt/POILookupModule.cpp b/libosmscout-client-qt/src/osmscoutclientqt/POILookupModule.cpp deleted file mode 100644 index 701d08fcf..000000000 --- a/libosmscout-client-qt/src/osmscoutclientqt/POILookupModule.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/* - OSMScout - a Qt backend for libosmscout and libosmscout-map - Copyright (C) 2018 Lukas Karas - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include - -#include - -#include - -#include -#include - -namespace osmscout { - -POILookupModule::POILookupModule(QThread *thread,DBThreadRef dbThread): - thread(thread), dbThread(dbThread) -{ - -} - -POILookupModule::~POILookupModule() -{ - if (thread!=QThread::currentThread()){ - qWarning() << "Destroy" << this << "from non incorrect thread;" << thread << "!=" << QThread::currentThread(); - } - if (thread!=nullptr){ - thread->quit(); - } -} - -template -LocationEntry buildLocationEntry(T obj, - QString dbPath, - osmscout::GeoCoord coordinates, - osmscout::GeoBox bbox) -{ - QString title; - QString altName; - QString objectType = QString::fromUtf8(obj->GetType()->GetName().c_str()); - const osmscout::FeatureValueBuffer &features=obj->GetFeatureValueBuffer(); - - if (const osmscout::NameFeatureValue *name=features.findValue(); - name!=nullptr){ - title=QString::fromStdString(name->GetLabel(osmscout::Locale(), 0)); - //std::cout << " \"" << name->GetLabel() << "\""; - } else if (const osmscout::OperatorFeatureValue *operatorVal=features.findValue(); - operatorVal!=nullptr) { - title=QString::fromStdString(operatorVal->GetLabel(osmscout::Locale(), 0)); - } else if (const osmscout::RefFeatureValue *ref=features.findValue(); - ref!=nullptr) { - title=QString::fromStdString(ref->GetLabel(osmscout::Locale(), 0)); - } - - if (const osmscout::NameAltFeatureValue *name=features.findValue(); - name!=nullptr) { - altName = QString::fromStdString(name->GetLabel(osmscout::Locale(), 0)); - } - - LocationEntry location(LocationEntry::typeObject, title, altName, objectType, QList(), - dbPath, coordinates, bbox); - location.addReference(obj->GetObjectFileRef()); - return LocationEntry(location); // explicit copy. some older compilers (GCC 7.5.0) fails when tries to use deleted move constructor -} - -QList POILookupModule::doPOIlookup(DBInstanceRef db, - osmscout::GeoBox searchBoundingBox, - osmscout::BreakerRef /*breaker*/, - QStringList types) -{ - QList result; - - osmscout::TypeInfoSet nodeTypes; - std::vector nodes; - osmscout::TypeInfoSet wayTypes; - std::vector ways; - osmscout::TypeInfoSet areaTypes; - std::vector areas; - - auto database=db->GetDatabase(); - if (!database){ - osmscout::log.Error() << "No db available"; - return result; - } - osmscout::TypeConfigRef typeConfig=database->GetTypeConfig(); - if (!typeConfig){ - osmscout::log.Error() << "No typeConfig available"; - return result; - } - - // prepare type set - for (const QString &typeName: types){ - osmscout::TypeInfoRef typeInfo=typeConfig->GetTypeInfo(typeName.toStdString()); - if (!typeInfo){ - osmscout::log.Warn() << "There is no type " << typeName.toStdString(); - continue; - } - if (typeInfo->CanBeArea()){ - areaTypes.Set(typeInfo); - } - if (typeInfo->CanBeWay()){ - wayTypes.Set(typeInfo); - } - if (typeInfo->CanBeNode()){ - nodeTypes.Set(typeInfo); - } - } - - // lookup objects - osmscout::POIService poiService(database); - try { - poiService.GetPOIsInArea(searchBoundingBox, - nodeTypes, - nodes, - wayTypes, - ways, - areaTypes, - areas); - } - catch (const std::exception& e) { - osmscout::log.Error() << "Failed to load POIs in area: " << e.what(); - return result; - } - - // build location entries - for (osmscout::AreaRef &area:areas) { - osmscout::GeoBox bbox=area->GetBoundingBox(); - osmscout::GeoCoord coordinates=bbox.GetCenter(); - - result << buildLocationEntry(area, QString::fromStdString(db->path), coordinates, bbox); - } - - for (osmscout::WayRef &way:ways) { - osmscout::GeoBox bbox=way->GetBoundingBox(); - osmscout::GeoCoord coordinates=bbox.GetCenter(); - - result << buildLocationEntry(way, QString::fromStdString(db->path), coordinates, bbox); - } - - for (osmscout::NodeRef &node:nodes) { - osmscout::GeoCoord coordinates=node->GetCoords(); - osmscout::GeoBox bbox; - bbox.Include(osmscout::GeoBox::BoxByCenterAndRadius(node->GetCoords(), Distance::Of(2.0))); - - result << buildLocationEntry(node, QString::fromStdString(db->path), coordinates, bbox); - } - - return result; -} - -void POILookupModule::lookupPOIRequest(int requestId, - osmscout::BreakerRef breaker, - osmscout::GeoCoord searchCenter, - QStringList types, - double maxDistance) -{ - osmscout::GeoBox searchBoundingBox=osmscout::GeoBox::BoxByCenterAndRadius(searchCenter, Distance::Of(maxDistance)); - - dbThread->RunSynchronousJob([&](const std::list& databases){ - - for (auto &db : databases) { - if (breaker && breaker->IsAborted()){ - emit lookupAborted(requestId); - break; - } - emit lookupResult(requestId, - doPOIlookup(db, searchBoundingBox, breaker, types)); - } - }); - - emit lookupFinished(requestId); -} -} diff --git a/libosmscout-client-qt/src/osmscoutclientqt/SearchLocationModel.cpp b/libosmscout-client-qt/src/osmscoutclientqt/SearchLocationModel.cpp index 3fdef28b2..b1dcbbbd7 100644 --- a/libosmscout-client-qt/src/osmscoutclientqt/SearchLocationModel.cpp +++ b/libosmscout-client-qt/src/osmscoutclientqt/SearchLocationModel.cpp @@ -140,8 +140,8 @@ void LocationListModel::addBatch(QList foundLocations) { assert(a != nullptr && b != nullptr); if (a->getLabel()==b->getLabel() && a->getDatabase()==b->getDatabase() && - a->getType()==LocationEntry::typeObject && - b->getType()==LocationEntry::typeObject){ + a->getType()==LocationInfo::Type::typeObject && + b->getType()==LocationInfo::Type::typeObject){ QJSValueList args; // to transfer ownership to QML, parent have to be null. copy constructor copy ownership @@ -350,11 +350,11 @@ void LocationListModel::setPattern(const QString& pattern) } if (searching){ // we are still waiting for previous request, postpone current - qDebug() << "Clear (" << locations.size() << ") postpone search" << pattern << "(default region:" << (defaultRegion?defaultRegion->qStringName():"NULL") << ")"; + qDebug() << "Clear (" << locations.size() << ") postpone search" << pattern << "(default region:" << QString::fromStdString(defaultRegion?defaultRegion->name():"NULL") << ")"; return; } - qDebug() << "Clear (" << locations.size() << ") search" << pattern << "(default region:" << (defaultRegion?defaultRegion->qStringName():"NULL") << ")"; + qDebug() << "Clear (" << locations.size() << ") search" << pattern << "(default region:" << QString::fromStdString(defaultRegion?defaultRegion->name():"NULL") << ")"; searching = true; lastRequestPattern = pattern; lastRequestDefaultRegion=defaultRegion; @@ -381,7 +381,7 @@ QVariant LocationListModel::data(const QModelIndex &index, int role) const case LabelRole: return location->getLabel(); case TypeRole: - if (location->getType()==LocationEntry::typeCoordinate) + if (location->getType()==LocationInfo::Type::typeCoordinate) return "coordinate"; else return location->getObjectType(); diff --git a/libosmscout-client-qt/src/osmscoutclientqt/SearchModule.cpp b/libosmscout-client-qt/src/osmscoutclientqt/SearchModule.cpp index 40f70c0e7..e137adb6d 100644 --- a/libosmscout-client-qt/src/osmscoutclientqt/SearchModule.cpp +++ b/libosmscout-client-qt/src/osmscoutclientqt/SearchModule.cpp @@ -68,7 +68,7 @@ void SearchLocationsRunnable::run() } osmscout::AdminRegionRef defaultRegion; - if (defaultRegionInfo && defaultRegionInfo->database==QString::fromStdString(db->path)){ + if (defaultRegionInfo && defaultRegionInfo->database==db->path){ defaultRegion=defaultRegionInfo->adminRegion; } @@ -317,7 +317,7 @@ bool FreeTextSearchRunnable::BuildLocationEntry(const osmscout::ObjectFileRef& o } */ - LocationEntry location(LocationEntry::typeObject, name, altName, objectType, adminRegionList, + LocationEntry location(LocationInfo::Type::typeObject, name, altName, objectType, adminRegionList, QString::fromStdString(db->path), coordinates, bbox); location.addReference(object); locations.append(location); @@ -354,7 +354,7 @@ bool SearchLocationsRunnable::BuildLocationEntry(const osmscout::LocationSearchR osmscout::log.Debug() << "address: " << label.toStdString(); - LocationEntry location(LocationEntry::typeObject, label, altName, objectType, adminRegionList, + LocationEntry location(LocationInfo::Type::typeObject, label, altName, objectType, adminRegionList, QString::fromStdString(db->path), coordinates, bbox); location.addReference(entry.address->object); locations.append(location); @@ -369,7 +369,7 @@ bool SearchLocationsRunnable::BuildLocationEntry(const osmscout::LocationSearchR osmscout::log.Debug() << "loc: " << loc.toStdString(); - LocationEntry location(LocationEntry::typeObject, loc, altName, objectType, adminRegionList, + LocationEntry location(LocationInfo::Type::typeObject, loc, altName, objectType, adminRegionList, QString::fromStdString(db->path), coordinates, bbox); for (auto object : entry.location->objects) { @@ -386,7 +386,7 @@ bool SearchLocationsRunnable::BuildLocationEntry(const osmscout::LocationSearchR } osmscout::log.Debug() << "poi: " << poi.toStdString(); - LocationEntry location(LocationEntry::typeObject, poi, altName, objectType, adminRegionList, + LocationEntry location(LocationInfo::Type::typeObject, poi, altName, objectType, adminRegionList, QString::fromStdString(db->path), coordinates, bbox); location.addReference(entry.poi->object); locations.append(location); @@ -398,7 +398,7 @@ bool SearchLocationsRunnable::BuildLocationEntry(const osmscout::LocationSearchR QString regionName=QString::fromStdString(entry.adminRegion->name); //=QString::fromUtf8(entry.adminRegion->name.c_str()); - LocationEntry location(LocationEntry::typeObject, regionName, altName, objectType, adminRegionList, + LocationEntry location(LocationInfo::Type::typeObject, regionName, altName, objectType, adminRegionList, QString::fromStdString(db->path), coordinates, bbox); osmscout::log.Debug() << "region: " << regionName.toStdString(); diff --git a/libosmscout-client/CMakeLists.txt b/libosmscout-client/CMakeLists.txt index 9e168fff4..9d5a36e2d 100644 --- a/libosmscout-client/CMakeLists.txt +++ b/libosmscout-client/CMakeLists.txt @@ -1,14 +1,17 @@ set(HEADER_FILES include/osmscoutclient/json/json.hpp include/osmscoutclient/json/json_fwd.hpp + include/osmscoutclient/AdminRegionInfo.h include/osmscoutclient/DBInstance.h include/osmscoutclient/DBJob.h include/osmscoutclient/DBThread.h + include/osmscoutclient/LocationInfo.h include/osmscoutclient/MapDirectory.h include/osmscoutclient/MapManager.h include/osmscoutclient/MapProvider.h include/osmscoutclient/ClientImportExport.h include/osmscoutclient/OnlineTileProvider.h + include/osmscoutclient/POILookupModule.h include/osmscoutclient/Settings.h include/osmscoutclient/VoiceProvider.h ) @@ -21,6 +24,7 @@ set(SOURCE_FILES src/osmscoutclient/MapManager.cpp src/osmscoutclient/MapProvider.cpp src/osmscoutclient/OnlineTileProvider.cpp + src/osmscoutclient/POILookupModule.cpp src/osmscoutclient/Settings.cpp src/osmscoutclient/VoiceProvider.cpp ) diff --git a/libosmscout-client/include/meson.build b/libosmscout-client/include/meson.build index 9165538d5..88eb3d036 100644 --- a/libosmscout-client/include/meson.build +++ b/libosmscout-client/include/meson.build @@ -3,14 +3,17 @@ osmscoutclientIncDir = include_directories('.') osmscoutclientHeader = [ 'osmscoutclient/json/json.hpp', 'osmscoutclient/json/json_fwd.hpp', + 'osmscoutclient/AdminRegionInfo.h', 'osmscoutclient/ClientImportExport.h', 'osmscoutclient/DBInstance.h', 'osmscoutclient/DBJob.h', 'osmscoutclient/DBThread.h', + 'osmscoutclient/LocationInfo.h', 'osmscoutclient/MapDirectory.h', 'osmscoutclient/MapManager.h', 'osmscoutclient/MapProvider.h', 'osmscoutclient/OnlineTileProvider.h', + 'osmscoutclient/POILookupModule.h', 'osmscoutclient/Settings.h', 'osmscoutclient/VoiceProvider.h' ] diff --git a/libosmscout-client-qt/include/osmscoutclientqt/AdminRegionInfo.h b/libosmscout-client/include/osmscoutclient/AdminRegionInfo.h similarity index 62% rename from libosmscout-client-qt/include/osmscoutclientqt/AdminRegionInfo.h rename to libosmscout-client/include/osmscoutclient/AdminRegionInfo.h index 34f658536..ac4168335 100644 --- a/libosmscout-client-qt/include/osmscoutclientqt/AdminRegionInfo.h +++ b/libosmscout-client/include/osmscoutclient/AdminRegionInfo.h @@ -1,8 +1,8 @@ -#ifndef OSMSCOUT_CLIENT_QT_ADMINREGIONINFO_H -#define OSMSCOUT_CLIENT_QT_ADMINREGIONINFO_H +#ifndef OSMSCOUT_CLIENT_ADMINREGIONINFO_H +#define OSMSCOUT_CLIENT_ADMINREGIONINFO_H /* - OSMScout - a Qt backend for libosmscout and libosmscout-map - Copyright (C) 2017 Lukas Karas + This source is part of the libosmscout library + Copyright (C) 2017 Lukas Karas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -19,52 +19,38 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include -#include #include -#include +#include #include namespace osmscout { /** - * \ingroup QtAPI + * \ingroup ClientAPI */ -class OSMSCOUT_CLIENT_QT_API AdminRegionInfo +struct OSMSCOUT_CLIENT_API AdminRegionInfo { -public: - QString database; + std::string database; osmscout::AdminRegionRef adminRegion; - QString type; //!< adminRegion->object's type + std::string type; //!< adminRegion->object's type int adminLevel{-1}; -public: std::string name() const { return adminRegion->name; } - QString qStringName() const - { - return QString::fromStdString(adminRegion->name); - } - std::string altName() const { return adminRegion->altName; } - - QString qStringAltName() const - { - return QString::fromStdString(adminRegion->altName); - } }; typedef std::shared_ptr AdminRegionInfoRef; } -#endif //OSMSCOUT_CLIENT_QT_ADMINREGIONINFO_H +#endif //OSMSCOUT_CLIENT_ADMINREGIONINFO_H diff --git a/libosmscout-client/include/osmscoutclient/LocationInfo.h b/libosmscout-client/include/osmscoutclient/LocationInfo.h new file mode 100644 index 000000000..559c91865 --- /dev/null +++ b/libosmscout-client/include/osmscoutclient/LocationInfo.h @@ -0,0 +1,55 @@ +#ifndef OSMSCOUT_CLIENT_LOCATIONDESCRIPTION_H +#define OSMSCOUT_CLIENT_LOCATIONDESCRIPTION_H + +/* + This source is part of the libosmscout library + Copyright (C) 2023 Lukáš Karas + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include + +#include + +namespace osmscout { + +/** + * \ingroup ClientAPI + */ +struct OSMSCOUT_CLIENT_API LocationInfo { + + enum class Type { + typeNone, + typeObject, + typeCoordinate + }; + + Type type; + std::string label; + std::string altName; // name in alternative language + std::string objectType; + std::vector adminRegionList; + std::string database; + std::vector references; + GeoCoord coord; + GeoBox bbox; + +}; + +} +#endif //OSMSCOUT_CLIENT_LOCATIONDESCRIPTION_H diff --git a/libosmscout-client/include/osmscoutclient/POILookupModule.h b/libosmscout-client/include/osmscoutclient/POILookupModule.h new file mode 100644 index 000000000..f89832ffc --- /dev/null +++ b/libosmscout-client/include/osmscoutclient/POILookupModule.h @@ -0,0 +1,74 @@ +#ifndef OSMSCOUT_CLIENT_POILOOKUPSERVICE_H +#define OSMSCOUT_CLIENT_POILOOKUPSERVICE_H +/* + OSMScout - a Qt backend for libosmscout and libosmscout-map + Copyright (C) 2018 Lukas Karas + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include +#include + +namespace osmscout { + +/** + * \ingroup QtAPI + */ +class OSMSCOUT_CLIENT_API POILookupModule: public AsyncWorker +{ +private: + DBThreadRef dbThread; + +public: + + using LookupResult = std::vector; + using LookupFuture = CancelableFuture; + + Signal lookupAborted; // lookupFinished; // lookupResult; // &types, + const Distance &maxDistance); + +private: + LookupResult doPOIlookup(DBInstanceRef db, + const GeoBox &searchBoundingBox, + const std::vector &types); + +}; + +} + +#endif //OSMSCOUT_CLIENT_POILOOKUPSERVICE_H diff --git a/libosmscout-client/src/meson.build b/libosmscout-client/src/meson.build index 5bc90b77d..4eca8c8d6 100644 --- a/libosmscout-client/src/meson.build +++ b/libosmscout-client/src/meson.build @@ -6,6 +6,7 @@ osmscoutclientSrc = [ 'src/osmscoutclient/MapManager.cpp', 'src/osmscoutclient/MapProvider.cpp', 'src/osmscoutclient/OnlineTileProvider.cpp', + 'src/osmscoutclient/POILookupModule.cpp', 'src/osmscoutclient/Settings.cpp', 'src/osmscoutclient/VoiceProvider.cpp' ] diff --git a/libosmscout-client/src/osmscoutclient/POILookupModule.cpp b/libosmscout-client/src/osmscoutclient/POILookupModule.cpp new file mode 100644 index 000000000..4edf7a267 --- /dev/null +++ b/libosmscout-client/src/osmscoutclient/POILookupModule.cpp @@ -0,0 +1,186 @@ +/* + OSMScout - a Qt backend for libosmscout and libosmscout-map + Copyright (C) 2018 Lukas Karas + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include + +#include + +namespace osmscout { + +POILookupModule::POILookupModule(DBThreadRef dbThread): + AsyncWorker("POILookupModule"), dbThread(dbThread) +{ + // no code +} + +POILookupModule::~POILookupModule() +{ + ThreadAssert(); +} + +template +LocationInfo buildLocationEntry(T obj, + const std::string &dbPath, + const GeoCoord &coordinates, + const GeoBox &bbox) +{ + std::string title; + std::string altName; + std::string objectType = obj->GetType()->GetName(); + const FeatureValueBuffer &features=obj->GetFeatureValueBuffer(); + + if (const NameFeatureValue *name=features.findValue(); + name!=nullptr){ + title=name->GetLabel(Locale(), 0); + //std::cout << " \"" << name->GetLabel() << "\""; + } else if (const OperatorFeatureValue *operatorVal=features.findValue(); + operatorVal!=nullptr) { + title=operatorVal->GetLabel(Locale(), 0); + } else if (const RefFeatureValue *ref=features.findValue(); + ref!=nullptr) { + title=ref->GetLabel(Locale(), 0); + } + + if (const NameAltFeatureValue *name=features.findValue(); + name!=nullptr) { + altName = name->GetLabel(Locale(), 0); + } + + return LocationInfo{LocationInfo::Type::typeObject, + title, + altName, + objectType, + std::vector(), + dbPath, + {obj->GetObjectFileRef()}, + coordinates, + bbox}; +} + +POILookupModule::LookupResult POILookupModule::doPOIlookup(DBInstanceRef db, + const GeoBox &searchBoundingBox, + const std::vector &types) +{ + LookupResult result; + + TypeInfoSet nodeTypes; + std::vector nodes; + TypeInfoSet wayTypes; + std::vector ways; + TypeInfoSet areaTypes; + std::vector areas; + + auto database=db->GetDatabase(); + if (!database){ + log.Error() << "No db available"; + return result; + } + TypeConfigRef typeConfig=database->GetTypeConfig(); + if (!typeConfig){ + log.Error() << "No typeConfig available"; + return result; + } + + // prepare type set + for (const auto &typeName: types){ + TypeInfoRef typeInfo=typeConfig->GetTypeInfo(typeName); + if (!typeInfo){ + log.Warn() << "There is no type " << typeName; + continue; + } + if (typeInfo->CanBeArea()){ + areaTypes.Set(typeInfo); + } + if (typeInfo->CanBeWay()){ + wayTypes.Set(typeInfo); + } + if (typeInfo->CanBeNode()){ + nodeTypes.Set(typeInfo); + } + } + + // lookup objects + POIService poiService(database); + try { + poiService.GetPOIsInArea(searchBoundingBox, + nodeTypes, + nodes, + wayTypes, + ways, + areaTypes, + areas); + } + catch (const std::exception& e) { + log.Error() << "Failed to load POIs in area: " << e.what(); + return result; + } + + // build location entries + for (AreaRef &area:areas) { + GeoBox bbox=area->GetBoundingBox(); + GeoCoord coordinates=bbox.GetCenter(); + + result.push_back(buildLocationEntry(area, db->path, coordinates, bbox)); + } + + for (WayRef &way:ways) { + GeoBox bbox=way->GetBoundingBox(); + GeoCoord coordinates=bbox.GetCenter(); + + result.push_back(buildLocationEntry(way, db->path, coordinates, bbox)); + } + + for (NodeRef &node:nodes) { + GeoCoord coordinates=node->GetCoords(); + GeoBox bbox; + bbox.Include(GeoBox::BoxByCenterAndRadius(node->GetCoords(), Distance::Of(2.0))); + + result.push_back(buildLocationEntry(node, db->path, coordinates, bbox)); + } + + return result; +} + +POILookupModule::LookupFuture POILookupModule::lookupPOIRequest(int requestId, + const GeoCoord &searchCenter, + const std::vector &types, + const Distance &maxDistance) +{ + return Async([=](Breaker &breaker) -> LookupResult { + LookupResult result; + GeoBox searchBoundingBox=GeoBox::BoxByCenterAndRadius(searchCenter, maxDistance); + + dbThread->RunSynchronousJob([&](const std::list& databases){ + for (auto &db : databases) { + if (breaker.IsAborted()){ + lookupAborted.Emit(requestId); + break; + } + auto partialResult=doPOIlookup(db, searchBoundingBox, types); + lookupResult.Emit(requestId,partialResult); + std::copy(partialResult.begin(), partialResult.end(), std::back_inserter(result)); + } + }); + + return result; + }); +} +} diff --git a/libosmscout/include/osmscout/async/AsyncWorker.h b/libosmscout/include/osmscout/async/AsyncWorker.h index 13ea33fe4..446e94e34 100644 --- a/libosmscout/include/osmscout/async/AsyncWorker.h +++ b/libosmscout/include/osmscout/async/AsyncWorker.h @@ -27,6 +27,7 @@ #include #include +#include namespace osmscout { @@ -58,6 +59,16 @@ namespace osmscout { void DeleteLater(); + std::thread::id GetThreadId() const + { + return thread.get_id(); + } + + void ThreadAssert() const + { + assert(std::this_thread::get_id()==thread.get_id()); + } + protected: template CancelableFuture Async(const std::function &task)