libosmscout  1.1.1
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 
31 #include <osmscout/MapPainter.h>
32 
33 #include <QtGui/QTextLayout>
34 
35 namespace osmscout {
36 
40 
41  class MapPainterBatchQt;
42 
47  {
48  friend class MapPainterBatchQt;
49 
51  friend QtLabelLayouter;
52 
53  private:
54  struct FollowPathHandle
55  {
56  bool closeWay;
57  size_t transStart;
58  size_t transEnd;
59  size_t i;
60  size_t nVertex;
61  size_t direction;
62  };
63  struct FontDescriptor
64  {
65  QString fontName;
66  size_t fontSize;
67  QFont::Weight weight;
68  bool italic;
69 
70  bool operator<(const FontDescriptor& other) const
71  {
72  return std::tie(fontName, fontSize, weight, italic) < std::tie(other.fontName, other.fontSize, other.weight, other.italic);
73  }
74  };
75 
76  private:
77  QPainter *painter{nullptr};
78 
79  QtLabelLayouter labelLayouter;
80 
86  QtLabelLayouter *delegateLabelLayouter{nullptr};
87 
88  std::map<std::string,QImage> images;
89  std::vector<QImage> patternImages;
91  std::vector<QBrush> patterns;
92  QMap<FontDescriptor,QFont> fonts;
93  std::vector<double> sin;
94 
95  std::mutex mutex;
96 
97  private:
98  QFont GetFont(const Projection& projection,
99  const MapParameter& parameter,
100  double fontSize);
101 
102  void SetFill(const Projection& projection,
103  const MapParameter& parameter,
104  const FillStyle& fillStyle);
105 
106  void SetBorder(const Projection& projection,
107  const MapParameter& parameter,
108  const BorderStyle& borderStyle);
109 
110  bool FollowPath(FollowPathHandle &hnd, double l, Vertex2D &origin);
111  void FollowPathInit(FollowPathHandle &hnd, Vertex2D &origin, size_t transStart, size_t transEnd,
112  bool isClosed, bool keepOrientation);
113 
114  void SetupTransformation(QPainter* painter,
115  const QPointF center,
116  const qreal angle,
117  const qreal baseline) const;
118 
119  osmscout::DoubleRectangle GlyphBoundingBox(const QGlyphRun &glyph) const;
120 
121  void DrawGlyph(QPainter *painter, const Glyph<QGlyphRun> &glyph) const;
122 
123  void DrawGlyphs(const Projection &projection,
124  const MapParameter &parameter,
125  const osmscout::PathTextStyleRef style,
126  const std::vector<osmscout::Glyph<QGlyphRun>> &glyphs);
127 
128  std::shared_ptr<QtLabel> Layout(const Projection& projection,
129  const MapParameter& parameter,
130  const std::string& text,
131  double fontSize,
132  double objectWidth,
133  bool enableWrapping = false,
134  bool contourLabel = false);
135 
136  QtLabelLayouter& GetLayouter();
137 
138  void DrawRectangle(int x, int y,
139  int width, int height,
140  const Color &color);
141 
142  protected:
143  bool HasIcon(const StyleConfig& styleConfig,
144  const Projection& projection,
145  const MapParameter& parameter,
146  IconStyle& style) override;
147 
148  bool HasPattern(const Projection& projection,
149  const MapParameter& parameter,
150  const FillStyle& style);
151 
152  double GetFontHeight(const Projection& projection,
153  const MapParameter& parameter,
154  double fontSize) override;
155 
156  void DrawGround(const Projection& projection,
157  const MapParameter& parameter,
158  const FillStyle& style) override;
159 
160  void DrawLabel(const Projection& projection,
161  const MapParameter& parameter,
162  const DoubleRectangle& labelRectangle,
163  const LabelData& label,
164  const QTextLayout& textLayout);
165 
166  void BeforeDrawing(const StyleConfig& styleConfig,
167  const Projection& projection,
168  const MapParameter& parameter,
169  const MapData& data) override;
170 
175  void RegisterRegularLabel(const Projection& projection,
176  const MapParameter& parameter,
177  const std::vector<LabelData>& labels,
178  const Vertex2D& position,
179  double objectWidth) override;
180 
184  void RegisterContourLabel(const Projection& projection,
185  const MapParameter& parameter,
186  const PathLabelData& label,
187  const LabelPath& labelPath) override;
188 
189  void DrawLabels(const Projection& projection,
190  const MapParameter& parameter,
191  const MapData& data) override;
192 
193  void DrawIcon(const IconStyle* style,
194  double centerX, double centerY,
195  double width, double height) override;
196 
197  void DrawSymbol(const Projection& projection,
198  const MapParameter& parameter,
199  const Symbol& symbol,
200  double x, double y) override;
201 
202  void DrawPath(const Projection& projection,
203  const MapParameter& parameter,
204  const Color& color,
205  double width,
206  const std::vector<double>& dash,
207  LineStyle::CapStyle startCap,
208  LineStyle::CapStyle endCap,
209  size_t transStart, size_t transEnd) override;
210 
211  void DrawContourSymbol(const Projection& projection,
212  const MapParameter& parameter,
213  const Symbol& symbol,
214  double space,
215  size_t transStart, size_t transEnd) override;
216 
217  void DrawArea(const Projection& projection,
218  const MapParameter& parameter,
219  const AreaData& area) override;
220 
221  public:
222  explicit MapPainterQt(const StyleConfigRef& styleConfig);
223  ~MapPainterQt() override;
224 
225  void DrawGroundTiles(const Projection& projection,
226  const MapParameter& parameter,
227  const std::list<GroundTile>& groundTiles,
228  QPainter* painter);
229 
230  bool DrawMap(const Projection& projection,
231  const MapParameter& parameter,
232  const MapData& data,
233  QPainter* painter);
234  };
235 
244  public MapPainterBatch<MapPainterQt*> {
245  public:
246  MapPainterBatchQt(size_t expectedCount);
247 
248  ~MapPainterBatchQt() override;
249 
250  bool paint(const Projection& projection,
251  const MapParameter& parameter,
252  QPainter* painter);
253  };
254 }
255 
256 #endif
Definition: LabelLayouter.h:144
Definition: MapPainterQt.h:243
#define OSMSCOUT_MAP_QT_API
Definition: MapQtImportExport.h:45
Definition: LabelLayouter.h:172
Definition: MapPainter.h:673
Definition: Projection.h:43
Definition: MapPainter.h:75
std::shared_ptr< PathTextStyle > PathTextStyleRef
Definition: Styles.h:877
Definition: Area.h:38
bool operator<(const TileCacheKey &a, const TileCacheKey &b)
std::shared_ptr< StyleConfig > StyleConfigRef
Definition: StyleConfig.h:849
Definition: MapPainter.h:87
Definition: MapPainterQt.h:46
Definition: LabelLayouter.h:129
Rectangle< double > DoubleRectangle
Definition: LabelLayouter.h:85
Same as previous, but from main database.
Definition: MapPainter.h:62
CapStyle
Definition: Styles.h:69