libosmscout  1.1.1
TiledMapRenderer.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_CLIENT_QT_TILEDMAPRENDERER_H
2 #define OSMSCOUT_CLIENT_QT_TILEDMAPRENDERER_H
3 
4 /*
5  OSMScout - a Qt backend for libosmscout and libosmscout-map
6  Copyright (C) 2010 Tim Teulings
7  Copyright (C) 2017 Lukas Karas
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */
23 
24 #include <QObject>
25 #include <QSettings>
26 
27 #include <osmscout/DataTileCache.h>
28 #include <osmscout/DBThread.h>
29 #include <osmscout/MapRenderer.h>
30 
32 
33 #include <atomic>
34 
35 namespace osmscout {
36 
38  Q_OBJECT
39 
40 private:
41  QString tileCacheDirectory;
42 
43  // tile caches
44  // Rendered tile is combined from both sources.
45  //
46  // Online cache may contain NULL images (QImage::isNull() is true) for areas
47  // covered by offline database and offline cache can contain NULL images
48  // for areas not covered by database.
49  //
50  // When offlineTileCache is invalidated, cache keeps unchanged,
51  // just its epoch is increased. When there is retrieved pixmap with
52  // old epoch from cache, it is used, but rendering request is triggered.
53  //
54  // Offline tiles should be in ARGB format on database area interface.
55  mutable QMutex tileCacheMutex;
56  TileCache onlineTileCache;
57  TileCache offlineTileCache;
58 
59  OsmTileDownloader *tileDownloader;
60 
61  std::atomic_bool onlineTilesEnabled;
62  std::atomic_bool offlineTilesEnabled;
63 
64  int screenWidth;
65  int screenHeight;
66 
67  // data loading request
68  DBLoadJob *loadJob;
69  uint32_t loadXFrom;
70  uint32_t loadXTo;
71  uint32_t loadYFrom;
72  uint32_t loadYTo;
73  MagnificationLevel loadZ;
74  size_t loadEpoch; // guarded by lock
75 
76  QColor unknownColor;
77 
78 public slots:
79  virtual void Initialize();
80  virtual void InvalidateVisualCache();
81  virtual void onStylesheetFilenameChanged();
82 
83  void onlineTileRequest(uint32_t zoomLevel, uint32_t xtile, uint32_t ytile);
84  void offlineTileRequest(uint32_t zoomLevel, uint32_t xtile, uint32_t ytile);
85  void tileDownloaded(uint32_t zoomLevel, uint32_t x, uint32_t y, QImage image, QByteArray downloadedData);
86  void tileDownloadFailed(uint32_t zoomLevel, uint32_t x, uint32_t y, bool zoomLevelOutOfRange);
87  void onDatabaseLoaded(osmscout::GeoBox boundingBox);
88  void onLoadJobFinished(QMap<QString,QMap<osmscout::TileKey,osmscout::TileRef>>);
89 
90  void onlineTileProviderChanged();
91  void onlineTilesEnabledChanged(bool);
92 
93  void onOfflineMapChanged(bool);
94 
95 private:
96 
97  DatabaseCoverage databaseCoverageOfTile(uint32_t zoomLevel, uint32_t xtile, uint32_t ytile);
98 
99 public:
100  TiledMapRenderer(QThread *thread,
101  SettingsRef settings,
102  DBThreadRef dbThread,
103  QString iconDirectory,
104  QString tileCacheDirectory,
105  size_t onlineTileCacheSize,
106  size_t offlineTileCacheSize);
107 
108  virtual ~TiledMapRenderer();
109 
116  virtual bool RenderMap(QPainter& painter,
117  const MapViewStruct& request);
118 };
119 
120 }
121 
122 #endif /* OSMSCOUT_CLIENT_QT_TILEDMAPRENDERER_H */
std::shared_ptr< Settings > SettingsRef
Definition: Settings.h:171
Definition: OsmTileDownloader.h:40
#define OSMSCOUT_CLIENT_QT_API
Definition: ClientQtImportExport.h:45
DatabaseCoverage
Definition: DBThread.h:83
Definition: Area.h:38
Definition: MapRenderer.h:72
Definition: DBThread.h:51
std::shared_ptr< DBThread > DBThreadRef
Definition: DBThread.h:239
Setup internal state of renderer for executing next steps with current projection and parameters...
Definition: MapPainter.h:57
Definition: TileCache.h:91
Definition: DBJob.h:58
Definition: TiledMapRenderer.h:37