libosmscout  1.1.1
MapRenderer.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_CLIENT_QT_MAPRENDERER_H
2 #define OSMSCOUT_CLIENT_QT_MAPRENDERER_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 
31 #include <osmscout/OverlayObject.h>
32 
33 namespace osmscout {
34 
39  Q_OBJECT
40 private:
41  osmscout::MercatorProjection renderProjection;
42  QMap<QString,QMap<osmscout::TileKey,osmscout::TileRef>> tiles;
43  osmscout::MapParameter *drawParameter;
44  QPainter *p;
45  bool success;
46  bool drawCanvasBackground;
47  bool renderBasemap;
48  std::vector<OverlayObjectRef> overlayObjects;
49 
50 public:
52  QMap<QString,QMap<osmscout::TileKey,osmscout::TileRef>> tiles,
53  osmscout::MapParameter *drawParameter,
54  QPainter *p,
55  std::vector<OverlayObjectRef> overlayObjects,
56  bool drawCanvasBackground=true,
57  bool renderBasemap=true);
58  virtual ~DBRenderJob();
59 
60  void Run(const osmscout::BasemapDatabaseRef& basemapDatabase,
61  const std::list<DBInstanceRef> &databases,
62  QReadLocker *locker) override;
63 
64  inline bool IsSuccess() const{
65  return success;
66  };
67 };
68 
72 class OSMSCOUT_CLIENT_QT_API MapRenderer : public QObject {
73  Q_OBJECT
74 
75 protected:
76  QThread *thread;
79  QMutex lock;
80 
81  double mapDpi;
82  bool renderSea;
83 
84  QString fontName;
85  double fontSize;
86  QString iconDirectory;
87  bool showAltLanguage{false};
88  QString units;
89 
90  mutable QMutex overlayLock;
91  std::map<int,OverlayObjectRef> overlayObjectMap; // <! map guarded by overlayLock, OverlayWay object is multithread
92 
93 signals:
94  void Redraw();
95  void TriggerDrawMap();
96 
97 public slots:
98  virtual void Initialize() = 0;
99 
100  virtual void InvalidateVisualCache() = 0;
101  virtual void onStylesheetFilenameChanged();
102 
103  virtual void onMapDPIChange(double dpi);
104  virtual void onRenderSeaChanged(bool);
105  virtual void onFontNameChanged(const QString&);
106  virtual void onFontSizeChanged(double);
107  virtual void onShowAltLanguageChanged(bool);
108  virtual void onUnitsChanged(const QString&);
109 
110 protected:
111  MapRenderer(QThread *thread,
112  SettingsRef settings,
113  DBThreadRef dbThread,
114  QString iconDirectory);
115 
116  osmscout::GeoBox overlayObjectsBox() const;
117 
118  void getOverlayObjects(std::vector<OverlayObjectRef> &objs,
119  osmscout::GeoBox requestBox) const;
120 
121 public:
122  virtual ~MapRenderer();
123 
130  virtual bool RenderMap(QPainter& painter,
131  const MapViewStruct& request) = 0;
132 
133  void addOverlayObject(int id, const OverlayObjectRef& obj);
134 
135  void removeOverlayObject(int id);
136  void removeAllOverlayObjects();
137 
138  std::map<int,OverlayObjectRef> getOverlayObjects() const;
139 };
140 
141 using MapRendererRef = std::shared_ptr<MapRenderer>;
142 
143 }
144 
145 #endif /* OSMSCOUT_CLIENT_QT_MAPRENDERER_H */
std::shared_ptr< Settings > SettingsRef
Definition: Settings.h:171
#define OSMSCOUT_CLIENT_QT_API
Definition: ClientQtImportExport.h:45
QString units
Definition: MapRenderer.h:88
bool IsSuccess() const
Definition: MapRenderer.h:64
DBThreadRef dbThread
Definition: MapRenderer.h:78
QMutex overlayLock
Definition: MapRenderer.h:90
Definition: Projection.h:333
QString iconDirectory
Definition: MapRenderer.h:86
double mapDpi
Definition: MapRenderer.h:81
Definition: Area.h:38
Definition: MapRenderer.h:72
Definition: DBThread.h:51
std::shared_ptr< DBThread > DBThreadRef
Definition: DBThread.h:239
Definition: DBJob.h:40
std::shared_ptr< OverlayObject > OverlayObjectRef
Definition: OverlayObject.h:232
Setup internal state of renderer for executing next steps with current projection and parameters...
Definition: MapPainter.h:57
QMutex lock
Definition: MapRenderer.h:79
double fontSize
Definition: MapRenderer.h:85
bool renderSea
Definition: MapRenderer.h:82
Definition: MapRenderer.h:38
SettingsRef settings
Definition: MapRenderer.h:77
QString fontName
Definition: MapRenderer.h:84
std::shared_ptr< MapRenderer > MapRendererRef
Definition: MapRenderer.h:141
QThread * thread
Definition: MapRenderer.h:76
std::shared_ptr< BasemapDatabase > BasemapDatabaseRef
Reference counted reference to an Database instance.
Definition: BasemapDatabase.h:88
std::map< int, OverlayObjectRef > overlayObjectMap
Definition: MapRenderer.h:91