libosmscout 1.1.1
Loading...
Searching...
No Matches
MapPainterQt.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_MAP_MAPPAINTERQT_H
2#define OSMSCOUT_MAP_MAPPAINTERQT_H
3
4/*
5 This source is part of the libosmscout-map library
6 Copyright (C) 2010 Tim Teulings
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 <mutex>
24#include <tuple>
25
26#include <QPainter>
27#include <QMap>
28
30
33
34#include <QtGui/QTextLayout>
35
36namespace osmscout {
37
41
43
48 {
49 friend class BatchMapPainterQt;
50
52 friend QtLabelLayouter;
53
54 private:
55 struct FollowPathHandle
56 {
57 bool closeWay;
58 size_t transStart;
59 size_t transEnd;
60 size_t i;
61 size_t nVertex;
62 size_t direction;
63 };
64 struct FontDescriptor
65 {
66 QString fontName;
67 size_t fontSize;
68 QFont::Weight weight;
69 bool italic;
70
71 bool operator<(const FontDescriptor& other) const
72 {
73 return std::tie(fontName, fontSize, weight, italic) < std::tie(other.fontName, other.fontSize, other.weight, other.italic);
74 }
75 };
76
77 private:
78 QPainter *painter{nullptr};
79
80 QtLabelLayouter labelLayouter;
81
87 QtLabelLayouter *delegateLabelLayouter{nullptr};
88
89 std::map<std::string,QImage,std::less<>> images;
91 std::vector<QImage> patternImages;
92 std::vector<QBrush> patterns;
93 QMap<FontDescriptor,QFont> fonts;
94 std::vector<double> sin;
95
96 std::mutex mutex;
97
98 private:
99 QFont GetFont(const Projection& projection,
100 const MapParameter& parameter,
101 double fontSize);
102
103 void SetFill(const Projection& projection,
104 const MapParameter& parameter,
105 const FillStyle& fillStyle);
106
107 void SetBorder(const Projection& projection,
108 const MapParameter& parameter,
109 const BorderStyle& borderStyle);
110
111 bool FollowPath(FollowPathHandle &hnd,
112 const CoordBufferRange& coordRange,
113 double l,
114 Vertex2D &origin);
115 void FollowPathInit(FollowPathHandle &hnd,
116 const CoordBufferRange& coordRange,
117 Vertex2D &origin,
118 bool isClosed,
119 bool keepOrientation);
120
121 void SetupTransformation(QPainter* painter,
122 const QPointF center,
123 const qreal angle,
124 const qreal baseline) const;
125
126 osmscout::ScreenVectorRectangle GlyphBoundingBox(const QGlyphRun &glyph) const;
127
128 void DrawGlyph(QPainter *painter, const Glyph<QGlyphRun> &glyph) const;
129
130 void DrawGlyphs(const Projection &projection,
131 const MapParameter &parameter,
132 const osmscout::PathTextStyleRef style,
133 const std::vector<osmscout::Glyph<QGlyphRun>> &glyphs);
134
135 std::shared_ptr<QtLabel> Layout(const Projection& projection,
136 const MapParameter& parameter,
137 const std::string& text,
138 double fontSize,
139 double objectWidth,
140 bool enableWrapping = false,
141 bool contourLabel = false);
142
143 QtLabelLayouter& GetLayouter();
144
145 void DrawRectangle(int x, int y,
146 int width, int height,
147 const Color &color);
148
149 protected:
151 const Projection& projection,
152 const MapParameter& parameter,
153 IconStyle& style) override;
154
155 bool HasPattern(const Projection& projection,
156 const MapParameter& parameter,
157 const FillStyle& style);
158
159 double GetFontHeight(const Projection& projection,
160 const MapParameter& parameter,
161 double fontSize) override;
162
163 void DrawGround(const Projection& projection,
164 const MapParameter& parameter,
165 const FillStyle& style) override;
166
167 void DrawLabel(const Projection& projection,
168 const MapParameter& parameter,
169 const ScreenVectorRectangle& labelRectangle,
170 const LabelData& label,
171 const QTextLayout& textLayout);
172
174 const Projection& projection,
175 const MapParameter& parameter,
176 const MapData& data) override;
177
182 void RegisterRegularLabel(const Projection& projection,
183 const MapParameter& parameter,
184 const ObjectFileRef& ref,
185 const std::vector<LabelData>& labels,
186 const Vertex2D& position,
187 double objectWidth) override;
188
192 void RegisterContourLabel(const Projection& projection,
193 const MapParameter& parameter,
194 const ObjectFileRef& ref,
195 const PathLabelData& label,
196 const LabelPath& labelPath) override;
197
198 void DrawLabels(const Projection& projection,
199 const MapParameter& parameter,
200 const MapData& data) override;
201
202 void DrawIcon(const IconStyle* style,
203 const Vertex2D& centerPos,
204 double width, double height) override;
205
206 void DrawSymbol(const Projection& projection,
207 const MapParameter& parameter,
208 const Symbol& symbol,
209 const Vertex2D& screenPos,
210 double scaleFactor) override;
211
212 void DrawPath(const Projection& projection,
213 const MapParameter& parameter,
214 const Color& color,
215 double width,
216 const std::vector<double>& dash,
217 LineStyle::CapStyle startCap,
218 LineStyle::CapStyle endCap,
219 const CoordBufferRange& coordRange) override;
220
221 void DrawContourSymbol(const Projection& projection,
222 const MapParameter& parameter,
223 const Symbol& symbol,
224 const ContourSymbolData& data) override;
225
226 void DrawArea(const Projection& projection,
227 const MapParameter& parameter,
228 const AreaData& area) override;
229
230 public:
232 ~MapPainterQt() override;
233
234 void DrawGroundTiles(const Projection& projection,
235 const MapParameter& parameter,
236 const std::list<GroundTile>& groundTiles,
237 QPainter* painter);
238
239 bool DrawMap(const Projection& projection,
240 const MapParameter& parameter,
241 const MapData& data,
242 QPainter* painter,
245 };
246
255 public BatchMapPainter<MapPainterQt*> {
256 public:
257 explicit BatchMapPainterQt(size_t expectedCount);
258
260
261 bool paint(const Projection& projection,
262 const MapParameter& parameter,
263 QPainter* painter);
264 };
265}
266
267#endif
#define OSMSCOUT_MAP_QT_API
Definition MapQtImportExport.h:45
BatchMapPainter(size_t expectedCount)
Definition BatchMapPainter.h:81
Definition MapPainterQt.h:255
bool paint(const Projection &projection, const MapParameter &parameter, QPainter *painter)
BatchMapPainterQt(size_t expectedCount)
Definition LabelLayouter.h:103
Definition LabelLayouter.h:57
Definition LabelLayouter.h:119
Definition LabelLayouter.h:147
Definition LabelLayouter.h:230
Definition LabelPath.h:44
MapPainter(const StyleConfigRef &styleConfig)
StyleConfigRef styleConfig
Reference to the style configuration to be used.
Definition MapPainter.h:250
void DrawContourSymbol(const Projection &projection, const MapParameter &parameter, const Symbol &symbol, const ContourSymbolData &data) override
void DrawLabels(const Projection &projection, const MapParameter &parameter, const MapData &data) override
void RegisterRegularLabel(const Projection &projection, const MapParameter &parameter, const ObjectFileRef &ref, const std::vector< LabelData > &labels, const Vertex2D &position, double objectWidth) override
double GetFontHeight(const Projection &projection, const MapParameter &parameter, double fontSize) override
void DrawIcon(const IconStyle *style, const Vertex2D &centerPos, double width, double height) override
bool HasPattern(const Projection &projection, const MapParameter &parameter, const FillStyle &style)
void BeforeDrawing(const StyleConfig &styleConfig, const Projection &projection, const MapParameter &parameter, const MapData &data) override
friend class BatchMapPainterQt
Definition MapPainterQt.h:49
bool DrawMap(const Projection &projection, const MapParameter &parameter, const MapData &data, QPainter *painter, RenderSteps startStep=RenderSteps::FirstStep, RenderSteps endStep=RenderSteps::LastStep)
void DrawLabel(const Projection &projection, const MapParameter &parameter, const ScreenVectorRectangle &labelRectangle, const LabelData &label, const QTextLayout &textLayout)
void DrawArea(const Projection &projection, const MapParameter &parameter, const AreaData &area) override
void RegisterContourLabel(const Projection &projection, const MapParameter &parameter, const ObjectFileRef &ref, const PathLabelData &label, const LabelPath &labelPath) override
void DrawPath(const Projection &projection, const MapParameter &parameter, const Color &color, double width, const std::vector< double > &dash, LineStyle::CapStyle startCap, LineStyle::CapStyle endCap, const CoordBufferRange &coordRange) override
void DrawGround(const Projection &projection, const MapParameter &parameter, const FillStyle &style) override
void DrawGroundTiles(const Projection &projection, const MapParameter &parameter, const std::list< GroundTile > &groundTiles, QPainter *painter)
MapPainterQt(const StyleConfigRef &styleConfig)
void DrawSymbol(const Projection &projection, const MapParameter &parameter, const Symbol &symbol, const Vertex2D &screenPos, double scaleFactor) override
bool HasIcon(const StyleConfig &styleConfig, const Projection &projection, const MapParameter &parameter, IconStyle &style) override
Definition LabelLayouter.h:46
Definition Projection.h:46
Index selectors by type and level.
Definition StyleConfig.h:552
Definition Area.h:39
LabelInstance< QGlyphRun, QTextLayout > QtLabelInstance
Definition MapPainterQt.h:40
std::shared_ptr< PathTextStyle > PathTextStyleRef
Definition Styles.h:890
std::shared_ptr< StyleConfig > StyleConfigRef
Definition StyleConfig.h:859
Label< QGlyphRun, QTextLayout > QtLabel
Definition MapPainterQt.h:39
RenderSteps
Definition MapPainter.h:64
@ LastStep
Definition MapPainter.h:92
@ FirstStep
Definition MapPainter.h:65
Glyph< QGlyphRun > QtGlyph
Definition MapPainterQt.h:38
bool operator<(const TileCacheKey &a, const TileCacheKey &b)
Definition MapPainter.h:174
Definition MapPainter.h:200
Definition LabelLayouterHelper.h:73