libosmscout  1.1.1
OSMScoutQt.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_CLIENT_QT_OSMSCOUTQT_H
2 #define OSMSCOUT_CLIENT_QT_OSMSCOUTQT_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 <QSettings>
24 
25 #include <osmscout/DataTileCache.h>
26 #include <osmscout/DBThread.h>
27 #include <osmscout/LookupModule.h>
28 #include <osmscout/MapRenderer.h>
29 #include <osmscout/Router.h>
30 #include <osmscout/SearchModule.h>
31 #include <osmscout/StyleModule.h>
34 #include <osmscout/VoiceManager.h>
36 
38 
39 #include <atomic>
40 
41 namespace osmscout {
42 
43 class OSMScoutQt;
44 
49 private:
50  QSettings *settingsStorage{nullptr};
51 
52  QString onlineTileProviders;
53  QString mapProviders;
54  QString voiceProviders;
55  QStringList mapLookupDirectories;
56  QString basemapLookupDirectory;
57  QString cacheLocation;
58  QString iconDirectory;
59  QStringList customPoiTypes;
60 
61  size_t onlineTileCacheSize{100};
62  size_t offlineTileCacheSize{200};
63 
64  QString voiceLookupDirectory;
65 
66  QString styleSheetDirectory;
67  bool styleSheetDirectoryConfigured{false};
68 
69  QString styleSheetFile;
70  bool styleSheetFileConfigured{false};
71 
72  QString appName{"UnspecifiedApp"};
73  QString appVersion{"v?"};
74 
75 public:
77 
78  virtual ~OSMScoutQtBuilder();
79 
80  inline OSMScoutQtBuilder& WithSettingsStorage(QSettings *providedStorage)
81  {
82  this->settingsStorage=providedStorage;
83  return *this;
84  }
85 
86  inline OSMScoutQtBuilder& WithOnlineTileProviders(const QString &onlineTileProviders)
87  {
88  this->onlineTileProviders=onlineTileProviders;
89  return *this;
90  }
91 
92  inline OSMScoutQtBuilder& WithMapProviders(const QString &mapProviders)
93  {
94  this->mapProviders=mapProviders;
95  return *this;
96  }
97 
98  inline OSMScoutQtBuilder& WithVoiceProviders(const QString &voiceProviders)
99  {
100  this->voiceProviders=voiceProviders;
101  return *this;
102  }
103 
104  inline OSMScoutQtBuilder& WithMapLookupDirectories(const QStringList &mapLookupDirectories)
105  {
106  this->mapLookupDirectories=mapLookupDirectories;
107  return *this;
108  }
109 
110  inline OSMScoutQtBuilder& WithBasemapLookupDirectory(const QString &basemapLookupDirectory)
111  {
112  this->basemapLookupDirectory=basemapLookupDirectory;
113  return *this;
114  }
115 
116  inline OSMScoutQtBuilder& WithVoiceLookupDirectory(const QString &voiceLookupDirectory)
117  {
118  this->voiceLookupDirectory=voiceLookupDirectory;
119  return *this;
120  }
121 
122  inline OSMScoutQtBuilder& AddMapLookupDirectories(const QString &mapLookupDirectory)
123  {
124  this->mapLookupDirectories << mapLookupDirectory;
125  return *this;
126  }
127 
128  inline OSMScoutQtBuilder& WithCustomPoiTypes(const QStringList &customPoiTypes)
129  {
130  this->customPoiTypes=customPoiTypes;
131  return *this;
132  }
133 
134  inline OSMScoutQtBuilder& AddCustomPoiType(const QString &typeName)
135  {
136  this->customPoiTypes << typeName;
137  return *this;
138  }
139 
140  inline OSMScoutQtBuilder& WithCacheLocation(const QString &cacheLocation)
141  {
142  this->cacheLocation=cacheLocation;
143  return *this;
144  }
145 
146  inline OSMScoutQtBuilder& WithIconDirectory(const QString &iconDirectory)
147  {
148  this->iconDirectory=iconDirectory;
149  return *this;
150  }
151 
152  inline OSMScoutQtBuilder& WithStyleSheetDirectory(const QString &styleSheetDirectory)
153  {
154  this->styleSheetDirectory=styleSheetDirectory;
155  this->styleSheetDirectoryConfigured=true;
156  return *this;
157  }
158 
159  inline OSMScoutQtBuilder& WithStyleSheetFile(QString styleSheetFile)
160  {
161  this->styleSheetFile=styleSheetFile;
162  this->styleSheetFileConfigured=true;
163  return *this;
164  }
165 
166  inline OSMScoutQtBuilder& WithTileCacheSizes(size_t onlineTileCacheSize,
167  size_t offlineTileCacheSize){
168  this->onlineTileCacheSize=onlineTileCacheSize;
169  this->offlineTileCacheSize=offlineTileCacheSize;
170  return *this;
171  }
172 
173  inline OSMScoutQtBuilder& WithUserAgent(const QString &appName,
174  const QString &appVersion){
175  this->appName=appName;
176  this->appVersion=appVersion;
177  return *this;
178  }
179 
180  bool Init();
181 };
182 
186 using OSMScoutQtBuilderRef = std::shared_ptr<OSMScoutQtBuilder>;
187 
194 };
195 
229 class OSMSCOUT_CLIENT_QT_API OSMScoutQt : public QObject {
230  Q_OBJECT
231  friend class OSMScoutQtBuilder;
232 
233 private:
234  SettingsRef settings;
235  MapManagerRef mapManager;
236  DBThreadRef dbThread;
237  QString iconDirectory;
238  QString cacheLocation;
239  size_t onlineTileCacheSize;
240  size_t offlineTileCacheSize;
241  QString userAgent;
242  std::atomic_int liveBackgroundThreads;
243  VoiceManagerRef voiceManager; // created lazy
244 
245 private:
246  OSMScoutQt(SettingsRef settings,
247  MapManagerRef mapManager,
248  QString basemapLookupDirectory,
249  QString iconDirectory,
250  QString cacheLocation,
251  size_t onlineTileCacheSize,
252  size_t offlineTileCacheSize,
253  QString userAgent,
254  QStringList customPoiTypes);
255 
256 public slots:
257  void threadFinished();
258 
259 public:
260  ~OSMScoutQt() override;
261 
279  QThread *makeThread(QString name);
280 
294  bool waitForReleasingResources(unsigned long mSleep, unsigned long maxCount) const;
295 
296  DBThreadRef GetDBThread() const;
297  SettingsRef GetSettings() const;
298  MapManagerRef GetMapManager() const;
299  VoiceManagerRef GetVoiceManager();
300 
301  LookupModule* MakeLookupModule();
302  MapRenderer* MakeMapRenderer(RenderingType type);
303  Router* MakeRouter();
304  NavigationModule* MakeNavigation();
305  SearchModule *MakeSearchModule();
306  StyleModule *MakeStyleModule();
307  POILookupModule *MakePOILookupModule();
308  ElevationModule *MakeElevationModule();
309 
310  QString GetUserAgent() const;
311  QString GetCacheLocation() const;
312  size_t GetOnlineTileCacheSize() const;
313  QString GetIconDirectory() const;
314 
315  static void RegisterQmlTypes(const char *uri="net.sf.libosmscout.map",
316  int versionMajor=1,
317  int versionMinor=0);
318 
319  static OSMScoutQtBuilder NewInstance();
320  static OSMScoutQt& GetInstance();
321  static void FreeInstance();
322 };
323 
324 }
325 
326 Q_DECLARE_METATYPE(osmscout::TileRef)
327 Q_DECLARE_METATYPE(osmscout::BreakerRef)
328 
329 #endif /* OSMSCOUT_CLIENT_QT_OSMSCOUTQT_H */
std::shared_ptr< Settings > SettingsRef
Definition: Settings.h:171
#define OSMSCOUT_CLIENT_QT_API
Definition: ClientQtImportExport.h:45
std::shared_ptr< Breaker > BreakerRef
Definition: Breaker.h:65
std::shared_ptr< Tile > TileRef
Definition: DataTileCache.h:443
OSMScoutQtBuilder & AddMapLookupDirectories(const QString &mapLookupDirectory)
Definition: OSMScoutQt.h:122
Definition: OSMScoutQt.h:192
Definition: SearchModule.h:137
std::shared_ptr< MapManager > MapManagerRef
Definition: MapManager.h:232
OSMScoutQtBuilder & WithUserAgent(const QString &appName, const QString &appVersion)
Definition: OSMScoutQt.h:173
OSMScoutQtBuilder & WithStyleSheetFile(QString styleSheetFile)
Definition: OSMScoutQt.h:159
OSMScoutQtBuilder & WithVoiceProviders(const QString &voiceProviders)
Definition: OSMScoutQt.h:98
OSMScoutQtBuilder & WithTileCacheSizes(size_t onlineTileCacheSize, size_t offlineTileCacheSize)
Definition: OSMScoutQt.h:166
OSMScoutQtBuilder & WithSettingsStorage(QSettings *providedStorage)
Definition: OSMScoutQt.h:80
std::shared_ptr< VoiceManager > VoiceManagerRef
Definition: VoiceManager.h:125
Definition: Area.h:38
Definition: OSMScoutQt.h:48
Definition: MapRenderer.h:72
OSMScoutQtBuilder & WithMapProviders(const QString &mapProviders)
Definition: OSMScoutQt.h:92
OSMScoutQtBuilder & WithIconDirectory(const QString &iconDirectory)
Definition: OSMScoutQt.h:146
std::shared_ptr< DBThread > DBThreadRef
Definition: DBThread.h:239
Definition: OSMScoutQt.h:229
OSMScoutQtBuilder & WithCustomPoiTypes(const QStringList &customPoiTypes)
Definition: OSMScoutQt.h:128
Definition: Router.h:46
OSMScoutQtBuilder & WithMapLookupDirectories(const QStringList &mapLookupDirectories)
Definition: OSMScoutQt.h:104
OSMScoutQtBuilder & WithBasemapLookupDirectory(const QString &basemapLookupDirectory)
Definition: OSMScoutQt.h:110
Definition: StyleModule.h:34
OSMScoutQtBuilder & WithCacheLocation(const QString &cacheLocation)
Definition: OSMScoutQt.h:140
OSMScoutQtBuilder & WithStyleSheetDirectory(const QString &styleSheetDirectory)
Definition: OSMScoutQt.h:152
Definition: ElevationModule.h:37
OSMScoutQtBuilder & WithVoiceLookupDirectory(const QString &voiceLookupDirectory)
Definition: OSMScoutQt.h:116
OSMScoutQtBuilder & WithOnlineTileProviders(const QString &onlineTileProviders)
Definition: OSMScoutQt.h:86
Definition: NavigationModule.h:54
std::shared_ptr< OSMScoutQtBuilder > OSMScoutQtBuilderRef
Definition: OSMScoutQt.h:186
Definition: LookupModule.h:48
OSMScoutQtBuilder & AddCustomPoiType(const QString &typeName)
Definition: OSMScoutQt.h:134
RenderingType
Definition: OSMScoutQt.h:191
Definition: OSMScoutQt.h:193
Definition: POILookupModule.h:33