libosmscout  1.1.1
LookupModule.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_CLIENT_QT_LOOKUPMODULE_H
2 #define OSMSCOUT_CLIENT_QT_LOOKUPMODULE_H
3 
4 /*
5  OSMScout - a Qt backend for libosmscout and libosmscout-map
6  Copyright (C) 2017 Lukas Karas
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  */
22 
23 #include <QObject>
24 #include <QThread>
25 #include <osmscout/DBThread.h>
27 
29 #include <iostream>
30 
31 namespace osmscout {
32 
34 public:
35  QString database;
37  QString name;
38  QString altName;
39  QString type;
41 };
42 
43 typedef std::shared_ptr<AdminRegionInfo> AdminRegionInfoRef;
44 
48 class OSMSCOUT_CLIENT_QT_API LookupModule:public QObject{
49  Q_OBJECT
50 
51  friend class SearchRunnable;
52 
53 public:
54 
62  NA1 = 1,
63  Country = 2,
64  Territory = 3,
65  State = 4,
66  NA5 = 5,
67  Region = 6,
68  District = 7,
69  Town = 8,
70  Neighbourhood = 9
71  };
72 
73  class ObjectInfo {
74  public:
75  QString type; // node / way / area
76  QString objectType;
77  QString name;
78  QString phone;
79  QString website;
80  QString addressNumber;
82  QStringList adminRegionList;
83  uint64_t id;
84  osmscout::GeoCoord center;
85  std::vector<osmscout::Point> points;
86  };
87 
88 private:
89  QMutex mutex;
90  QThread *thread;
91  DBThreadRef dbThread;
92  DBLoadJob *loadJob;
93  MapViewStruct view;
94  QRectF filterRectangle;
95  std::map<QString,std::map<osmscout::FileOffset,AdminRegionInfoRef>> adminRegionCache;
96 
97 signals:
98  void initialisationFinished(const DatabaseLoadedResponse& response);
99  void viewObjectsLoaded(const MapViewStruct&,
100  const QList<LookupModule::ObjectInfo> &objects);
101 
102  void objectsLoaded(const LocationEntry&,
103  const QList<LookupModule::ObjectInfo> &objects);
104 
105  void locationDescription(const osmscout::GeoCoord location,
106  const QString database,
107  const osmscout::LocationDescription description,
108  const QStringList regions);
109  void locationDescriptionFinished(const osmscout::GeoCoord location);
110 
111  void locationAdminRegions(const osmscout::GeoCoord location,
112  QList<AdminRegionInfoRef> adminRegionList);
113  void locationAdminRegionFinished(const osmscout::GeoCoord location);
114 
115 public slots:
116  void requestObjectsOnView(const MapViewStruct&, const QRectF &filterRectangle);
117  void requestObjects(const LocationEntry&, bool reverseLookupAddresses);
118  void onDatabaseLoaded(QString dbPath,QList<osmscout::TileRef> tiles);
119  void onLoadJobFinished(QMap<QString,QMap<osmscout::TileKey,osmscout::TileRef>> tiles);
120 
131  void requestLocationDescription(const osmscout::GeoCoord location);
132 
143  void requestRegionLookup(const osmscout::GeoCoord location);
144 
145 public:
146  LookupModule(QThread *thread,DBThreadRef dbThread);
147  virtual ~LookupModule();
148 
149 private:
150 
151  void addObjectInfo(QList<ObjectInfo> &objectList, // output
152  QString type,
153  const ObjectFileRef &ref,
154  const std::vector<osmscout::Point> &points,
155  const osmscout::GeoCoord &center,
156  const osmscout::TypeInfoRef &objectType,
157  const osmscout::FeatureValueBuffer &features,
158  const std::map<ObjectFileRef,LocationDescriptionService::ReverseLookupResult> &reverseLookupMap,
159  LocationServiceRef &locationService,
160  std::map<osmscout::FileOffset,osmscout::AdminRegionRef> &regionMap)
161  {
162  ObjectInfo info;
163  //std::cout << " - "<<type.toStdString()<<": " << o->GetType()->GetName() << " " << ref.GetName();
164 
165  info.type=type;
166  info.objectType=QString::fromStdString(objectType->GetName());
167  info.id=ref.GetFileOffset();
168 
169  const osmscout::NameFeatureValue *name=features.findValue<osmscout::NameFeatureValue>();
170  if (name!=nullptr){
171  info.name=QString::fromStdString(name->GetLabel(Locale(), 0));
172  }
173  const osmscout::PhoneFeatureValue *phone=features.findValue<osmscout::PhoneFeatureValue>();
174  if (phone!=nullptr){
175  info.phone=QString::fromStdString(phone->GetPhone());
176  }
177  const osmscout::WebsiteFeatureValue *website=features.findValue<osmscout::WebsiteFeatureValue>();
178  if (website!=nullptr){
179  info.website=QString::fromStdString(website->GetWebsite());
180  }
181  const osmscout::AddressFeatureValue *address=features.findValue<osmscout::AddressFeatureValue>();
182  if (address!=nullptr){
183  info.addressNumber=QString::fromStdString(address->GetAddress());
184  }
185  const auto &it=reverseLookupMap.find(ref);
186  if (it!=reverseLookupMap.end()){
187  info.adminRegionList=BuildAdminRegionList(locationService, it->second.adminRegion, regionMap);
188  info.reverseLookupRef=std::make_shared<LocationDescriptionService::ReverseLookupResult>(it->second);
189  }
190  info.center=center;
191  info.points=points;
192 
193  objectList << info;
194  }
195 
196  template<class T> void addObjectInfo(QList<ObjectInfo> &objectList, // output
197  QString type,
198  const ObjectFileRef &ref,
199  const std::vector<osmscout::Point> &points,
200  const osmscout::GeoCoord &center,
201  const T &o,
202  const std::map<ObjectFileRef,LocationDescriptionService::ReverseLookupResult> &reverseLookupMap,
203  LocationServiceRef &locationService,
204  std::map<osmscout::FileOffset,osmscout::AdminRegionRef> &regionMap)
205  {
206  addObjectInfo(objectList,type,ref,points,center,o->GetType(),o->GetFeatureValueBuffer(),reverseLookupMap,locationService,regionMap);
207  }
208 
209  void addObjectInfo(QList<ObjectInfo> &objectList, // output
210  const NodeRef &node,
211  const std::map<ObjectFileRef,LocationDescriptionService::ReverseLookupResult> &reverseLookupMap,
212  LocationServiceRef &locationService,
213  std::map<osmscout::FileOffset,osmscout::AdminRegionRef> &regionMap);
214 
215  void addObjectInfo(QList<ObjectInfo> &objectList, // output
216  const WayRef &way,
217  const std::map<ObjectFileRef,LocationDescriptionService::ReverseLookupResult> &reverseLookupMap,
218  LocationServiceRef &locationService,
219  std::map<osmscout::FileOffset,osmscout::AdminRegionRef> &regionMap);
220 
221  void addObjectInfo(QList<ObjectInfo> &objectList, // output
222  const AreaRef &area,
223  const std::map<ObjectFileRef,LocationDescriptionService::ReverseLookupResult> &reverseLookupMap,
224  LocationServiceRef &locationService,
225  std::map<osmscout::FileOffset,osmscout::AdminRegionRef> &regionMap);
226 
227  AdminRegionInfoRef buildAdminRegionInfo(DBInstanceRef &db,const osmscout::AdminRegionRef &region);
228 
229  QList<AdminRegionInfoRef> BuildAdminRegionInfoList(AdminRegionInfoRef &bottom,
230  std::map<osmscout::FileOffset,AdminRegionInfoRef> &regionInfoMap);
231 
232  static QStringList BuildAdminRegionList(const osmscout::LocationServiceRef& locationService,
233  const osmscout::AdminRegionRef& adminRegion,
234  std::map<osmscout::FileOffset,osmscout::AdminRegionRef> &regionMap);
235 
236  static QStringList BuildAdminRegionList(const osmscout::AdminRegionRef& adminRegion,
237  std::map<osmscout::FileOffset,osmscout::AdminRegionRef> regionMap);
238 
239  void filterObjectInView(const osmscout::MapData &data,
240  QList<ObjectInfo> &objectList);
241 };
242 
246 typedef std::shared_ptr<LookupModule> LookupModuleRef;
247 
248 }
249 
250 #endif /* OSMSCOUT_CLIENT_QT_LOOKUPMODULE_H */
osmscout::AdminRegionRef adminRegion
Definition: LookupModule.h:36
QString name
Definition: LookupModule.h:37
#define OSMSCOUT_CLIENT_QT_API
Definition: ClientQtImportExport.h:45
Definition: TypeFeatures.h:1468
std::shared_ptr< Node > NodeRef
Definition: Node.h:124
std::string GetPhone() const
Definition: TypeFeatures.h:1558
Definition: TypeFeatures.h:1539
QString website
Definition: LookupModule.h:79
Definition: SearchModule.h:41
QString database
Definition: LookupModule.h:35
LocationDescriptionService::ReverseLookupRef reverseLookupRef
Definition: LookupModule.h:81
std::shared_ptr< Way > WayRef
Definition: Way.h:202
std::shared_ptr< LookupModule > LookupModuleRef
Definition: LookupModule.h:246
QString type
Definition: LookupModule.h:75
int adminLevel
Definition: LookupModule.h:40
Definition: Area.h:38
std::string GetAddress() const
Definition: TypeFeatures.h:402
Definition: DBThread.h:51
osmscout::GeoCoord center
Definition: LookupModule.h:84
std::shared_ptr< DBThread > DBThreadRef
Definition: DBThread.h:239
std::shared_ptr< Area > AreaRef
Definition: Area.h:358
QString addressNumber
Definition: LookupModule.h:80
uint64_t id
Definition: LookupModule.h:83
QStringList adminRegionList
Definition: LookupModule.h:82
std::shared_ptr< ReverseLookupResult > ReverseLookupRef
Definition: LocationDescriptionService.h:369
std::vector< osmscout::Point > points
Definition: LookupModule.h:85
QString objectType
Definition: LookupModule.h:76
Definition: LocationEntry.h:42
QString name
Definition: LookupModule.h:77
Definition: TypeFeatures.h:382
Definition: DBJob.h:58
std::shared_ptr< AdminRegionInfo > AdminRegionInfoRef
Definition: LookupModule.h:43
QString type
Definition: LookupModule.h:39
Definition: TypeFeatures.h:34
std::string GetWebsite() const
Definition: TypeFeatures.h:1487
Definition: LookupModule.h:73
std::shared_ptr< TypeInfo > TypeInfoRef
Definition: TypeConfig.h:58
Definition: DBThread.h:74
QString phone
Definition: LookupModule.h:78
std::shared_ptr< LocationService > LocationServiceRef
Definition: LocationService.h:317
Definition: LookupModule.h:48
std::shared_ptr< DBInstance > DBInstanceRef
Definition: DBInstance.h:217
Definition: LookupModule.h:33
std::shared_ptr< AdminRegion > AdminRegionRef
Definition: Location.h:83
QString altName
Definition: LookupModule.h:38
std::string GetLabel(const Locale &, size_t) const override
Definition: TypeFeatures.h:59
AdminRegionLevel
Definition: LookupModule.h:61