libosmscout 1.1.1
Loading...
Searching...
No Matches
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
26
27#include <osmscoutclient/MapManager.h>
28#include <osmscoutclient/DBThread.h>
29#include <osmscoutclient/POILookupModule.h>
30
41
43
44#include <atomic>
45
46namespace osmscout {
47
48class OSMScoutQt;
49
54private:
55 QSettings *settingsStorage{nullptr};
56
57 QStringList onlineTileProviders;
58 QStringList mapProviders;
59 QStringList voiceProviders;
60 QStringList mapLookupDirectories;
61 QString basemapLookupDirectory;
62 QString cacheLocation;
63 QString iconDirectory;
64 QStringList customPoiTypes;
65
66 size_t onlineTileCacheSize{100};
67 size_t offlineTileCacheSize{200};
68
69 QString voiceLookupDirectory;
70
71 QString styleSheetDirectory;
72 bool styleSheetDirectoryConfigured{false};
73
74 QString styleSheetFile;
75 bool styleSheetFileConfigured{false};
76
77 QString appName{"UnspecifiedApp"};
78 QString appVersion{"v?"};
79
80public:
82
84
89 inline OSMScoutQtBuilder& WithSettingsStorage(QSettings *providedStorage)
90 {
91 this->settingsStorage=providedStorage;
92 return *this;
93 }
94
95 inline OSMScoutQtBuilder& AddOnlineTileProviders(const QString &onlineTileProviders)
96 {
97 this->onlineTileProviders << onlineTileProviders;
98 return *this;
99 }
100
101 inline OSMScoutQtBuilder& AddMapProviders(const QString &mapProviders)
102 {
103 this->mapProviders << mapProviders;
104 return *this;
105 }
106
107 inline OSMScoutQtBuilder& AddVoiceProviders(const QString &voiceProviders)
108 {
109 this->voiceProviders << voiceProviders;
110 return *this;
111 }
112
113 inline OSMScoutQtBuilder& WithMapLookupDirectories(const QStringList &mapLookupDirectories)
114 {
115 this->mapLookupDirectories=mapLookupDirectories;
116 return *this;
117 }
118
119 inline OSMScoutQtBuilder& WithBasemapLookupDirectory(const QString &basemapLookupDirectory)
120 {
121 this->basemapLookupDirectory=basemapLookupDirectory;
122 return *this;
123 }
124
125 inline OSMScoutQtBuilder& WithVoiceLookupDirectory(const QString &voiceLookupDirectory)
126 {
127 this->voiceLookupDirectory=voiceLookupDirectory;
128 return *this;
129 }
130
131 inline OSMScoutQtBuilder& AddMapLookupDirectories(const QString &mapLookupDirectory)
132 {
133 this->mapLookupDirectories << mapLookupDirectory;
134 return *this;
135 }
136
137 inline OSMScoutQtBuilder& WithCustomPoiTypes(const QStringList &customPoiTypes)
138 {
139 this->customPoiTypes=customPoiTypes;
140 return *this;
141 }
142
143 inline OSMScoutQtBuilder& AddCustomPoiType(const QString &typeName)
144 {
145 this->customPoiTypes << typeName;
146 return *this;
147 }
148
149 inline OSMScoutQtBuilder& WithCacheLocation(const QString &cacheLocation)
150 {
151 this->cacheLocation=cacheLocation;
152 return *this;
153 }
154
155 inline OSMScoutQtBuilder& WithIconDirectory(const QString &iconDirectory)
156 {
157 this->iconDirectory=iconDirectory;
158 return *this;
159 }
160
161 inline OSMScoutQtBuilder& WithStyleSheetDirectory(const QString &styleSheetDirectory)
162 {
163 this->styleSheetDirectory=styleSheetDirectory;
164 this->styleSheetDirectoryConfigured=true;
165 return *this;
166 }
167
168 inline OSMScoutQtBuilder& WithStyleSheetFile(QString styleSheetFile)
169 {
170 this->styleSheetFile=styleSheetFile;
171 this->styleSheetFileConfigured=true;
172 return *this;
173 }
174
175 inline OSMScoutQtBuilder& WithTileCacheSizes(size_t onlineTileCacheSize,
176 size_t offlineTileCacheSize){
177 this->onlineTileCacheSize=onlineTileCacheSize;
178 this->offlineTileCacheSize=offlineTileCacheSize;
179 return *this;
180 }
181
182 inline OSMScoutQtBuilder& WithUserAgent(const QString &appName,
183 const QString &appVersion){
184 this->appName=appName;
185 this->appVersion=appVersion;
186 return *this;
187 }
188
189 bool Init();
190};
191
195using OSMScoutQtBuilderRef = std::shared_ptr<OSMScoutQtBuilder>;
196
204
238class OSMSCOUT_CLIENT_QT_API OSMScoutQt : public QObject {
239 Q_OBJECT
240 friend class OSMScoutQtBuilder;
241
242private:
243 SettingsRef settings;
244 MapManagerRef mapManager;
245 DBThreadRef dbThread;
246 QString iconDirectory;
247 QString cacheLocation;
248 size_t onlineTileCacheSize;
249 size_t offlineTileCacheSize;
250 QString userAgent;
251 std::atomic_int liveBackgroundThreads;
252
253 std::mutex mutex;
254 MapDownloaderRef mapDownloader; // created lazy, guarded by mutex
255 VoiceManagerRef voiceManager; // created lazy, guarded by mutex
256
257private:
258 OSMScoutQt(SettingsRef settings,
259 MapManagerRef mapManager,
260 QString basemapLookupDirectory,
261 QString iconDirectory,
262 QString cacheLocation,
263 size_t onlineTileCacheSize,
264 size_t offlineTileCacheSize,
265 QString userAgent,
266 QStringList customPoiTypes);
267
268public slots:
270
271public:
272 ~OSMScoutQt() override;
273
291 QThread *makeThread(QString name);
292
306 bool waitForReleasingResources(unsigned long mSleep, unsigned long maxCount) const;
307
308 DBThreadRef GetDBThread() const;
309 SettingsRef GetSettings() const;
310 MapManagerRef GetMapManager() const;
313
320 POILookupModule *MakePOILookupModule();
323
324 QString GetUserAgent() const;
325 QString GetCacheLocation() const;
327 QString GetIconDirectory() const;
328
329 static void RegisterQmlTypes(const char *uri="net.sf.libosmscout.map",
330 int versionMajor=1,
331 int versionMinor=0);
332
334 static OSMScoutQt& GetInstance();
335 static void FreeInstance();
336};
337
338}
339
340#endif /* OSMSCOUT_CLIENT_QT_OSMSCOUTQT_H */
#define OSMSCOUT_CLIENT_QT_API
Definition ClientQtImportExport.h:45
Definition ElevationModule.h:41
Definition IconLookup.h:66
Definition LookupModule.h:47
Definition MapRenderer.h:85
Definition NavigationModule.h:67
OSMScoutQtBuilder & WithBasemapLookupDirectory(const QString &basemapLookupDirectory)
Definition OSMScoutQt.h:119
OSMScoutQtBuilder & WithStyleSheetDirectory(const QString &styleSheetDirectory)
Definition OSMScoutQt.h:161
OSMScoutQtBuilder & WithIconDirectory(const QString &iconDirectory)
Definition OSMScoutQt.h:155
OSMScoutQtBuilder & WithCustomPoiTypes(const QStringList &customPoiTypes)
Definition OSMScoutQt.h:137
OSMScoutQtBuilder & WithTileCacheSizes(size_t onlineTileCacheSize, size_t offlineTileCacheSize)
Definition OSMScoutQt.h:175
OSMScoutQtBuilder & WithMapLookupDirectories(const QStringList &mapLookupDirectories)
Definition OSMScoutQt.h:113
OSMScoutQtBuilder & WithSettingsStorage(QSettings *providedStorage)
Definition OSMScoutQt.h:89
OSMScoutQtBuilder & WithStyleSheetFile(QString styleSheetFile)
Definition OSMScoutQt.h:168
OSMScoutQtBuilder & WithVoiceLookupDirectory(const QString &voiceLookupDirectory)
Definition OSMScoutQt.h:125
OSMScoutQtBuilder & AddCustomPoiType(const QString &typeName)
Definition OSMScoutQt.h:143
OSMScoutQtBuilder & WithCacheLocation(const QString &cacheLocation)
Definition OSMScoutQt.h:149
OSMScoutQtBuilder & AddMapLookupDirectories(const QString &mapLookupDirectory)
Definition OSMScoutQt.h:131
OSMScoutQtBuilder & AddMapProviders(const QString &mapProviders)
Definition OSMScoutQt.h:101
OSMScoutQtBuilder & AddVoiceProviders(const QString &voiceProviders)
Definition OSMScoutQt.h:107
OSMScoutQtBuilder & AddOnlineTileProviders(const QString &onlineTileProviders)
Definition OSMScoutQt.h:95
OSMScoutQtBuilder & WithUserAgent(const QString &appName, const QString &appVersion)
Definition OSMScoutQt.h:182
Definition OSMScoutQt.h:238
SearchModule * MakeSearchModule()
IconLookup * MakeIconLookup()
static OSMScoutQtBuilder NewInstance()
bool waitForReleasingResources(unsigned long mSleep, unsigned long maxCount) const
LookupModule * MakeLookupModule()
DBThreadRef GetDBThread() const
~OSMScoutQt() override
StyleModule * MakeStyleModule()
MapManagerRef GetMapManager() const
QString GetCacheLocation() const
VoiceManagerRef GetVoiceManager()
MapRenderer * MakeMapRenderer(RenderingType type)
static void FreeInstance()
QThread * makeThread(QString name)
static OSMScoutQt & GetInstance()
friend class OSMScoutQtBuilder
Definition OSMScoutQt.h:240
QString GetIconDirectory() const
MapDownloaderRef GetMapDownloader()
static void RegisterQmlTypes(const char *uri="net.sf.libosmscout.map", int versionMajor=1, int versionMinor=0)
NavigationModule * MakeNavigation()
ElevationModule * MakeElevationModule()
POILookupModule * MakePOILookupModule()
QString GetUserAgent() const
size_t GetOnlineTileCacheSize() const
SettingsRef GetSettings() const
Definition Router.h:50
Definition SearchModule.h:157
Definition StyleModule.h:37
RenderingType
Definition OSMScoutQt.h:200
std::shared_ptr< VoiceManager > VoiceManagerRef
Definition VoiceManager.h:125
std::shared_ptr< OSMScoutQtBuilder > OSMScoutQtBuilderRef
Definition OSMScoutQt.h:195
std::shared_ptr< MapDownloader > MapDownloaderRef
Definition MapDownloader.h:128
@ PlaneRendering
Definition OSMScoutQt.h:201
@ TiledRendering
Definition OSMScoutQt.h:202
Definition Area.h:39